EFF has created a wonderful tool called CertBot to automate the retrieval and installation of letsencrypt certificates. The documentation is really good but it did require a little trial and error to get things working. Here’s a walkthrough with some of the gotcha’s I encountered.
Why do I need CertBot?
Letsencrypt certificates are only valid for 90 days. The verification and update process is a tedious process to complete manually. CertBot automates the retrieval and renewing certificates, it has a built-in webserver which can stand-in during the verification step, and it can modify your web server config and install the certificates if you happen to be using nginx or apache 2.4
Before you start, you should apply all software updates for your OS and restart. One of the updates overwrote a config file I customized which made the web server fail to start.
I was using CentOS 6 which doesn’t have a built-in package of CertBot. EFF also provides a version which can install its own dependencies called “CertBot Auto”.
Here’s how to install that:
me@vps:~$ wget https://dl.eff.org/certbot-auto me@vps:~$ chmod a=rx ./certbot-auto me@vps:~$ ./certbot-auto --help
I’d also recommend moving “certbot-auto” into “/usr/local/bin” so it’s available to other users or cron scripts.
me@vps:~$ mv ./certbot-auto /usr/local/bin/certbot
The docs are great. Have a look. https://certbot.eff.org/docs/using.html
My site redirects all traffic to https which breaks the verification process which needs to happen over http. The “standalone” mode solves this. It requires that you stop the web server and cert-bot will then answer on port 80 to complete the registration process. The CLI also defines pre-update and post-update “hooks” which can be used to stop and start your web server automatically to minimise down time.
For my domain this looked something like:
me@vps:~$ certbot certonly --standalone -d www.your.site --pre-hook "service httpd stop" --post-hook "service httpd start"
If you’re setup includes both http and https, you can use apache to serve the verification files.
sudo certbot-auto certonly --webroot -w /var/www/vhosts/default/html -d www.your.site -d your.site
You can include up to 10 domains on each certificate.
Where does your certificate get stored?
Good question. On CentOS, certbot creates a /etc/letsencrypt folder. Each certificate you generate will have a folder in the “live” folder. The commands above created a /etc/letsencrypt/live/www.your.site with your certificates files.
Here’s what you’ll need to add to your httpd.conf or virtual host to use this new certificate.
#Using letsencrypt certificates. SSLCertificateFile /etc/letsencrypt/live/www.your.site/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.your.site/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/www.your.site/chain.pem
The last thing to setup is cron task to automate renewal of our certificate(s).
“certbot renew -n” attempts to renew any certificates expiring in less than 30 days. The -n makes it non-interactive which is ideal cron task.
And that’s it. You’re all setup to take advantage of a letsencrypt certificate with centos and apache 2.2.
It was much easier than I though and after a lot of poking through the documentation I was able to piece together what needed to be done. Hopefully this saves you a few hours and a couple of server alerts.
Just one more thing. Ever heard of CCA?
One more wrinkle here is CCA checking. These freely available certificates mean that it’s not that hard to create a certificate which appears valid for a popular website. CCA checking adds a DNS record which informs certbot and other clients which authorities are allowed to register certificates for a given domain. All letsencrypt CAs will require this step after Sept. 2017. Because this requires a new DNS record type, not every host or registry is ready for this. I’m using namescheap for my .site address and it’s currently unsupported. Check with your domain registrar or whoever is providing your DNS service if they support CCA records. You might have to choose a new DNS provider if your registrar doesn’t if you want to continue using letsencrypt certificates.