Skip to content

Instantly share code, notes, and snippets.

@figassis
Created March 14, 2017 19:43
Show Gist options
  • Save figassis/41063b1c79b89a7e9b142175c78f5cac to your computer and use it in GitHub Desktop.
Save figassis/41063b1c79b89a7e9b142175c78f5cac to your computer and use it in GitHub Desktop.
Install SSL certificates on Ubuntu with Letsencrypt
#!/bin/bash
#Install/issue letsencrypt certificates on Ubuntu 16.04
if [ $# -ne 2 ]; then
echo Usage: $0 domain email
exit 1
fi
domain=$1
email=$2
status=`dpkg -s letsencrypt | grep Status`
#Renewal cron assumes no nginx is using port 443. Please modify accordingly for apache and others
cronjob='0 */12 * * * root service nginx stop && /opt/certbot-auto renew --quiet --no-self-upgrade && service nginx start'
if [ "$status" != "Status: install ok installed" ]; then
sudo apt-get -y install letsencrypt
sudo echo $cronjob > /etc/cron.d/letsencrypt
fi
#Certificates will be stored in /etc/letsencrypt/live/domain
sudo /opt/certbot-auto certonly -n --standalone -d $domain -m $email --agree-tos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment