Certbot ist das offizielle Tool zum Verwalten von Let's Encrypt-Zertifikaten. Es automatisiert Erstellung und Erneuerung.

Certbot installieren

Ubuntu/Debian

apt update
apt install certbot

Mit Apache-Plugin

apt install python3-certbot-apache

Mit Nginx-Plugin

apt install python3-certbot-nginx

CentOS/AlmaLinux

dnf install certbot python3-certbot-nginx

Zertifikat für Apache

Automatisch (empfohlen)

certbot --apache -d example.com -d www.example.com

Certbot: 1. Verifiziert Domain-Besitz 2. Erstellt Zertifikat 3. Konfiguriert Apache 4. Aktiviert HTTPS

Nur Zertifikat (manuell konfigurieren)

certbot certonly --apache -d example.com

Zertifikat für Nginx

Automatisch

certbot --nginx -d example.com -d www.example.com

Nur Zertifikat

certbot certonly --nginx -d example.com

Standalone-Modus

Wenn kein Webserver läuft:

certbot certonly --standalone -d example.com

Wichtig: Port 80 muss frei sein.

Webroot-Modus

Für komplexere Setups:

certbot certonly --webroot -w /var/www/html -d example.com

Certbot legt eine Datei in .well-known/acme-challenge/ ab.

Nginx-Konfiguration für Webroot

location /.well-known/acme-challenge/ {
    root /var/www/certbot;
}

Zertifikate anzeigen

certbot certificates

Ausgabe:

Certificate Name: example.com
  Domains: example.com www.example.com
  Expiry Date: 2024-04-20
  Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
  Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem

Zertifikatsdateien

Nach Erstellung unter /etc/letsencrypt/live/example.com/:

| Datei | Beschreibung | |-------|--------------| | cert.pem | Zertifikat | | chain.pem | Intermediate-Zertifikat | | fullchain.pem | Zertifikat + Chain | | privkey.pem | Privater Schlüssel |

Nginx-Konfiguration

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}

Apache-Konfiguration

<VirtualHost *:443>
    ServerName example.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>

Automatische Erneuerung

Let's Encrypt-Zertifikate sind 90 Tage gültig. Certbot erneuert automatisch.

Timer prüfen

systemctl status certbot.timer

Manuell testen

certbot renew --dry-run

Cronjob (falls kein systemd)

crontab -e
0 3 * * * certbot renew --quiet

Hooks bei Erneuerung

Webserver neu laden

Bei /etc/letsencrypt/renewal/example.com.conf:

[renewalparams]
# ...
post_hook = systemctl reload nginx

Mit Befehlszeile

certbot renew --post-hook "systemctl reload nginx"

Deploy-Hook (nur bei Erneuerung)

certbot renew --deploy-hook "systemctl reload nginx"

Wildcard-Zertifikate

Für *.example.com:

certbot certonly --manual --preferred-challenges dns -d "*.example.com" -d example.com

Sie müssen einen TXT-Record bei Ihrem DNS-Provider setzen.

Mit DNS-Plugin (automatisch)

Für Cloudflare:

apt install python3-certbot-dns-cloudflare

Credentials in /etc/letsencrypt/cloudflare.ini:

dns_cloudflare_api_token = DEIN_TOKEN
chmod 600 /etc/letsencrypt/cloudflare.ini

certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
  -d "*.example.com" -d example.com

Mehrere Domains

Im selben Zertifikat

certbot --nginx -d example.com -d www.example.com -d mail.example.com

Separate Zertifikate

certbot --nginx -d example.com
certbot --nginx -d andere-domain.de

Zertifikat löschen

certbot delete --cert-name example.com

Häufige Probleme

"Challenge failed"

  • DNS zeigt nicht auf Server
  • Port 80 blockiert
  • Webserver-Konfiguration falsch

Prüfen:

dig example.com +short
curl -I http://example.com/.well-known/acme-challenge/test

"Rate limit exceeded"

Zu viele Anfragen in kurzer Zeit. Warten Sie eine Stunde.

Für Tests:

certbot --nginx --staging -d example.com

"Unauthorized"

Meist DNS-Problem oder falsche Server-Konfiguration.

Best Practices

1. Redirects einrichten

HTTP auf HTTPS:

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name$request_uri;
}

2. HSTS aktivieren

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

3. Erneuerung testen

certbot renew --dry-run

4. Monitoring

Zertifikats-Ablauf überwachen:

echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates

5. Staging für Tests

certbot --staging -d test.example.com

Staging hat keine Rate-Limits.

Certbot-Befehle

| Aktion | Befehl | |--------|--------| | Neues Zertifikat | certbot --nginx -d domain.de | | Nur Zertifikat | certbot certonly --nginx -d domain.de | | Zertifikate anzeigen | certbot certificates | | Erneuerung testen | certbot renew --dry-run | | Manuell erneuern | certbot renew | | Zertifikat löschen | certbot delete --cert-name domain.de |

Alternative: acme.sh

Leichtgewichtige Alternative zu Certbot:

curl https://get.acme.sh | sh

acme.sh --issue -d example.com -w /var/www/html
acme.sh --install-cert -d example.com \
  --key-file /etc/ssl/private/example.key \
  --fullchain-file /etc/ssl/certs/example.crt \
  --reloadcmd "systemctl reload nginx"

Fazit

Certbot macht SSL-Zertifikate einfach. Die automatische Erneuerung sorgt für stets gültige Zertifikate. Einmal eingerichtet, läuft alles automatisch - Sie müssen sich um nichts mehr kümmern.