letsencrypt bietet die Möglichkeit kostenlos 3-Monate gültige SSL/TLS-Zertifikate zu beziehen.
Es existieren mehrere Clients, die unterschiedliche Methoden und Automatisierungsgrade unterstützen.
Comparison of 10 ACME / Let's Encrypt Clients
offizieller Client (certbot): Die offizielle Client-Software muss direkt auf dem Server gestartet werden (funktioniert also nicht für shared-Hosting sondern nur bei vhosts/root-Servern mit shell-Zugang) und unterstützt. Im standalone-Modus muss der laufende Webserver angehalten werden, es existieren jedoch integrierte Modi für Webserver wie Apache.
Eine detaillierte Liste für alle verbreiteten Plattformen führt die eff auf.
Da letsencrypt hat die Methode TLS-SNI-01 entfernt, daher ist nun mindestens certbot –version >= 0.28 nötig.
apt install certbot python3-certbot-apache python3-certbot-nginx
Der cronjob liegt in /etc/cron.d/certbot
.
Bei Debian sind in allen älteren stabilen Releases (vor Debian 9 / stretch) veraltete Versionen von certbot (bzw. als virtuelles Paket letsencrypt) in den Paketquellen enthalten. Daher ist die generische Methode via git zu verwenden.
apt install git git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt
apt-get update apt-get install -y software-properties-common add-apt-repository universe add-apt-repository -y ppa:certbot/certbot apt-get update apt-get install -y python-certbot-nginx
letsencrypt aufrufen:
generisch:
certbot --rsa-key-size 3072 -d DOMAIN.tld -d www.DOMAIN.tld
Die wichtigsten hooks:
Verzeichnisse: /etc/letsencrypt/renewal-hooks/{pre,post,deploy} (z.B. /etc/letsencrypt/renewal-hooks/deploy/allservices.sh)
Beispiel: bei standalone-Variante Webserver lighttpd (der keine Integration hat) stoppen 1):
certbot certonly --pre-hook "systemctl stop lighttpd" --post-hook "systemctl start lighttpd" --rsa-key-size 3072 -d DOMAIN.tld -d www.DOMAIN.tld
Es können auch mehrere Befehle (innerhalb eines hooks) angegeben werden:
--pre-hook "service apache2 stop ; service postfix stop"
https://eff-certbot.readthedocs.io/en/stable/using.html#renewing-certificates
Zertifikate verlinken:
ln -s /etc/letsencrypt/live/DOMAIN/fullchain.pem letsencryptchain.pem ln -s /etc/letsencrypt/live/DOMAIN/cert.pem /etc/apache2/DOMAIN.crt ln -s /etc/letsencrypt/live/DOMAIN/privkey.pem /etc/apache2/DOMAIN.key
Vorraussetzung ist ein v2 acme-Client 2), direkt per git:
aptitude install git git clone https://github.com/letsencrypt/letsencrypt
Client holt ein Zertifikat für *.DOMAIN.tld und DOMAIN.tld:
./letsencrypt/letsencrypt-auto certonly -d DOMAIN.tld -d *.DOMAIN.tld --manual --preferred-challenges dns
Zur Verifikation müssen zwei (!) DNS TXT-Records als _acme-challenge.DOMAIN.tld angelegt werden. Den Inhalt Inhalt legt der Client fest (hier ein Beispiel für „ApKINd5_XvyTvIqFXechXhbH7RebdR01hw5YhTxfQxd“)
Please deploy a DNS TXT record under the name _acme-challenge.DOMAIN.tld with the following value: ApKINd5_XvyTvIqFXechXhbH7RebdR01hw5YhTxfQxd Before continuing, verify the record is deployed. ------------------------------------------------------------------------------- Press Enter to Continue
Die Verlängerung lässt sich auch skripten. Dazu gibt es mehrere Varianten:
Der Befehl/das Skript sollte in /etc/crontab
(oder include-Datei / Benutzer-crontab) eingetragen werden.
[renewalparams] ... authenticator = standalone post_hook = systemctl start apache2 pre_hook = systemctl stop apache2
apt install python3-certbot-apache
certbot certonly --apache --deploy-hook "systemctl restart apache2" -d $Domain
/etc/letsencrypt/renewal/$Domain.conf
# [...] authenticator = apache deploy_hook = systemctl restart apache2
apt install python3-certbot-nginx
certbot certonly --nginx --deploy-hook "systemctl restart nginx" -d $Domain
/etc/letsencrypt/renewal/$Domain.conf
# [...] authenticator = nginx deploy_hook = systemctl restart nginx
authenticator = webroot [[webroot_map]] $Domain = /var/www/default/html
1x pro Woche:
12 4 * * 1 root certbot renew -q
Variante mit zufälliger Wartezeit: /etc/cron.d/certbot
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew
Die Verlängerung der Zertifikate funktioniert aber der Service der sie benutzt wird oft nicht vor Ablauf des Zertifikats neu gestartet? Dafür sind die hooks da, inbesondere der deploy_hook.
Falls diese fehlen korrigiert das folgende playbook die deploy_hook (und optional noch die pre_hook or post_hook):
gist: <html><script src=„https://gist.github.com/stefanux/11955353ea4f8002b73e433cbb5dc72e.js“></script></html>