Skip to content

Instantly share code, notes, and snippets.

@aamnah
Created April 24, 2020 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aamnah/2cc2eb8f052d8f5f1d380d34f2230be8 to your computer and use it in GitHub Desktop.
Save aamnah/2cc2eb8f052d8f5f1d380d34f2230be8 to your computer and use it in GitHub Desktop.
Script to install Letsencrypt certs non-interactively

Install SSL certificates non-interactively

Use this script as part of any installation script. I use it as part of my script for settting up a virtualhost for a domain/website on Apache

tl;dr

you need these additional flags

  • --non-interactive
  • --agree-tos
  • --register-unsafely-without-email or --email ${SSL_EMAIL}
SSL_EMAIL='info@mydomain.com' # if no email, use the --register-unsafely-without-email flag
DOMAINS='mydomain.com www.mydomain.com' # comma or space separated list of domains
SERVER='nginx'
installCertbot() {
# install Let's Encrypt Certbot
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-${SERVER}
sudo certbot --${SERVER}
}
installSSL() {
# install SSL
certbot --${SERVER} --non-interactive --agree-tos --email ${SSL_EMAIL} --domains ${DOMAINS}
}
installCertbot
installSSL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment