Server Tools: SSL Certificates
Let's Encrypt certificates with Server Tools: create via certbot for Apache, wildcard via DNS challenge, delete, list, check expiry, daily renewal cron job and all limitations.
SSL Certificates
SSL management uses certbot with the Apache plugin.
ssl create,ssl deleteandssl renewonly run withST_WEBSERVER=apache. Withnginxthey abort with... only supports Apache ... Nginx SSL support is not yet implemented.ssl wildcarddoes not check the webserver backend and runs with both backends, but it needs a configured DNS provider.ssl listandssl checkonly read certbot or/etc/letsencryptand also work with both backends.
Create a certificate
server-tools ssl create --domain example.com
server-tools ssl create --domain example.com --email admin@example.com
Flow:
- The domain is checked. An Apache VHost
<domain>.confmust exist for it, otherwise the command aborts. - If certbot is not installed, the tool installs the packages
certbotandpython3-certbot-apacheviaapt-get. - The email address is determined in this order:
--email,ST_CERTBOT_EMAIL,webmaster@<domain>. If the address is invalid, the tool useswebmaster@<domain>with a warning. certbot --apache -d <domain> --non-interactive --agree-tos --email <address>.- For proxy VHosts, the tool sets the targets
https://localhost,https://127.0.0.1andhttps://[::1]inProxyPassandProxyPassReverseof the generated<domain>-le-ssl.confback tohttp://, because the backend usually does not speak TLS. - Apache is reloaded.
The certificate only covers the given domain. Aliases of the VHost are not included.
Wildcard certificate
server-tools ssl wildcard --domain example.com --provider cloudflare
Requirements and flow:
- The provider comes from
--providerorST_DNS_PROVIDER. Supported:cloudflare,digitalocean,route53,google,linode,ovh. - If the package
python3-certbot-dns-<provider>is missing, it is installed viaapt-get. - The file with the API credentials must exist:
ST_DNS_CREDENTIALS_FILEor/root/.certbot-dns-<provider>.ini. If it is missing, the tool shows an example of the content forcloudflareanddigitalocean. certbot certonly --dns-<provider> --dns-<provider>-credentials <file> -d <domain> -d *.<domain> --non-interactive --agree-tos, withST_CERTBOT_EMAILorwebmaster@<domain>.
There is no --email option for wildcard certificates. The tool does not set up VHost SSL and does not change any Apache configuration. You have to include the certificate in a VHost yourself.
Delete a certificate
server-tools ssl delete --domain example.com
The certificate under /etc/letsencrypt/live/<domain> must exist. After the prompt the tool calls certbot delete --cert-name <domain>, removes /etc/apache2/sites-available/<domain>-le-ssl.conf and reloads Apache. The file <domain>.conf is left untouched.
List and check expiry
server-tools ssl list
server-tools ssl check --days 14
list prints certbot certificates. check reads all certificates in /etc/letsencrypt/live/ and shows those that expire in at most --days days (default 30) as <domain>: expires in <n> days. Already expired certificates appear with a negative number of days.
Set up automatic renewal
server-tools ssl renew
The command does not renew by itself, it sets up the renewal:
| File | Content |
|---|---|
/usr/local/bin/ssl-renewal.sh |
Calls certbot renew --quiet --no-self-upgrade --apache, then reloads apache2 and writes to /var/log/ssl-renewal.log |
/etc/cron.d/ssl-renewal |
30 3 * * * root /usr/local/bin/ssl-renewal.sh, daily at 03:30 |
Existing files are overwritten without a prompt. To test:
sudo certbot renew --dry-run
Recreate all certificates (menu only)
The menu offers "Recreate all certificates (Apache mode)". The tool finds all certificates in /etc/letsencrypt/live/ for which an Apache VHost exists and asks All certificates will be deleted and recreated!. Then, for each domain, the SSL site and <domain>-le-ssl.conf are removed, Apache is reloaded, all certificates are deleted and requested again via certbot --apache. At the end it prints Results: <success>/<total> successful.
During the process the domains are reachable without HTTPS. If requesting a domain again fails, it stays without a certificate.