81

I am writing a bash script which bootstraps the whole project infrastructure in the freshly installed server and i want to configure ssl installation with letcecrypt certbot. After I execute line:

certbot --nginx -d $( get_server_name ) -d www.$( get_server_name ).com

I get prompted for few questions. Can certbot be run without any interactions while passing some of the params as arguments or something ?

0

2 Answers 2

133

You can run certbot 'silently' by adding the following options:

--non-interactive --agree-tos -m [email protected]

The full list of config options is available here:

https://certbot.eff.org/docs/using.html

7
  • 12
    also include '--domains' May 16, 2019 at 12:41
  • 2
    Keep in mind that --non-interactive is not fail-proof, and the certificate will still fail to generate if the 3 mandatory flags are missing (see my answer for more info). Nov 6, 2019 at 11:20
  • Did not work. I got this error Missing command line flags. For non-interactive execution, you will need to specify a plugin on the command line. Run with '--help plugins' to see a list of options, and see https://eff.org/letsencrypt-plugins for more detail on what the plugins do and how to use them.
    – Ahmed
    Nov 7, 2019 at 17:20
  • 3
    Ahmed, you're missing --apache, or --nginx, or whatever server you're using. I found the "also include --domains" comment insufficient, by the way - wasn't clear to me that the server name needs to follow it. Here's my full command format, which worked (with root): certbot --nginx --non-interactive --agree-tos --domains example.com --email [email protected]
    – DHW
    Dec 20, 2019 at 3:51
  • @Ahmed Can you help me what's the mean The Name Server domain is not reachable from the Internet because there is a firewall or filtering router that is blocking connections to port 53 on this host for both UDP and TCP connections. The firewall configuration must permit connections on this port from any host on the Internet for the DNS to function properly.
    – Kwall
    May 17, 2021 at 20:03
36

There are several inline flags and "subcommands" (their nickname) provided by Certbot that can help to automate the process of generating free SSL certificates using Bash or shell scripts.

The most relevant flag as mentioned by @match is:

  • --noninteractive ...or alternatively... --non-interactive

However in reality this flag is not very helpful, because it doesn't do very much. If there are critical flags missing from your script, for example, the certificate will still fail to generate. Frankly, I think it would be better for Certbot to cancel the above flag, because it's rather misleading.

Here are the minimum flags required:

  1. --agree-tos
  2. --register-unsafely-without-email ...or... -m [email protected]
  3. -d example.com and/or -d www.example.com

You also must specify what type of Let's Encrypt installer plugin (environment) you want, for example you can choose from "standalone" or "manual" etc... for most cases, like a WordPress web server, you should choose "webroot" so that Certbot can easily verify ownership via the public root (make sure access to /.well-known* is not blocked):

--webroot -w /var/www/html/

Here is the complete command we use in SlickStack to install SSL certs:

## install Certbot SSL certificate ##
certbot certonly --noninteractive --agree-tos --cert-name slickstack -d ${SITE_TLD} -d www.${SITE_TLD} -d staging.${SITE_TLD} -d dev.${SITE_TLD} --register-unsafely-without-email --webroot -w /var/www/html/

In our case we hardcode the --cert-name to be slickstack because only one website is installed on each VPS server, so it makes other server admin tasks (and scripts) easier to manage. However, if you are installing several domains and SSL certs on the same server, you could change the subcommand --cert-name to be named after each TLD domain instead, etc. This affects the SSL directory names, thus helping to keep your files/folders nice and tidy.

3
  • 1
    NICE :) certbot certonly --noninteractive --agree-tos --cert-name ${SITE_TLD} -d ${SITE_DOMAIN_ONE} -d ${SITE_DOMAIN_TWO} -m ${SSL_EMAIL} --webroot -w /var/www/html/
    – Dr Deo
    Jun 3, 2020 at 18:34
  • sudo certbot --noninteractive --agree-tos --no-eff-email --cert-name domain.com --apache --no-redirect -d domain.com -d www.domain.com -m [email protected]
    – Dr Deo
    Jun 12, 2020 at 9:29
  • the error message is misleading, as it led me to believe I could make a separate invocation using only the --agree-tos and -m options to get that out of the way, and then subsequently would not need it. That does not seem to be the case. On a different host I never need to use this and it was long enough ago I don't recall what I did.
    – Michael
    Mar 5, 2023 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.