Insbesondere in der heutigen Zeit tragen (kostenlose) Zertifikate erheblich zur Reputation eurer Website bei. In der folgenden Anleitung erläutere ich, wie ich Zertifikate ohne & mit der Verwendung von Cloudflare nutze.
Um den Prozess zu vereinfachen, empfehle ich bereits im voraus vHosts angelegt zu haben.
1. Zu Beginn aktualisieren wir alle Pakete auf dem Server.
apt update && apt upgrade -y
2. Anschließend installieren wir certbot.
apt -y install certbot
3. Nachdem die Installation durchgeführt wurde, könnt ihr mit dem folgenden Befehl eure Zertifikate erstellen.
certbot
Durch die bereits angelegten vHosts könnt ihr nun eure Domains auswählen.
Sofern die Zertifikate erfolgreich erstellt worden sind, erhaltet ihr folgende Meldung:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/linuxpirat.de/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/linuxpirat.de/privkey.pem
Your certificate will expire on 2022-07-17. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again. To non-interactively renew *all* of your
certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Die Zertifikate werden automatisch erneuert, manuell können diese jedoch mit certbot renew erneuert werden.
Zertifikate mit Cloudflare nutzen
Durch die Nutzung eines DNS-Dienstes wie beispielsweise Cloudflare ist die Verwendung von den Zertifikaten leider nicht ganz so simpel.
Bei der ersten Methode könnt ihr das Zertifikat beantragen. Anschließend müssen händisch TXT-Records erstellt werden.
certbot -d linuxpirat.de --manual --preferred-challenges dns certonly
Please deploy a DNS TXT record under the name
_acme-challenge.linuxpirat.de with the following value:
75fbd40640a99925d20efa1d1d23ae2750968fd4
Once this is deployed,
Press ENTER to continue

Nachdem der Wert in einem TXT-Record ist, könnt ihr nach einer kurzen Wartezeit mit Enter bestätigen und den Record wieder löschen.
Bei erstmaliger Erstellung müsst ihr noch folgende Werte im Cloudflare User-Panel anpassen:




Ihr habt es geschafft! Nun hat eure Website über Cloudflare ein gültiges Zertifikat. Ungünstigerweise ist es immer ein wenig nervig, die Records händisch einzutragen und wieder zu löschen. Vergisst man mal die Erneuerung, können Besucher nicht auf eure Website.
Zum Glück gibt es für das Problem auch eine Lösung, denn mittels der API von Cloudflare und einem certbot-Plugin werden die Einträge automatisch erstellt und wieder gelöscht. Dafür müsst ihr folgendes Paket installieren
apt install certbot python3-certbot-dns-cloudflare
Je nach Webserver, den ihr verwendet, ist noch eine kleine Anpassung nötig. Solltet ihr standardmäßig nginx benutzen, ist keine Anpassung nötig. Bei Apache entsteht jedoch folgendes Problem: das Plugin von certbot nutzt nginx, bei simultaner Ausführung haben die beiden Webserver jedoch dieselben Ports von 80 beziehungsweise 443. Installiert daher nginx, öffnet die default Konfiguration von nginx und ändert den Port zu einem nicht benutzen.
apt install nginx -y
nano /etc/nginx/sites-available/default

Nun sollte es keine Probleme geben, wenn man standardmäßig Apache nutzt.
Damit sich das Plugin in euren Account einloggen kann, müssen wir noch die Zugangsdaten hinterlegen.
cd
mkdir .credentials
nano /root/.credentials/cloudflare.ini
chmod 600 /root/.credentials/cloudflare.ini
In der neu erstellten cloudflare.ini Datei tragt ihr euren Global API Key von Cloudflare ein.
# Cloudflare API credentials used by Certbot
dns_cloudflare_email = [email protected]
dns_cloudflare_api_key = 111111111111111111111111111111
Abschließend könnt ihr eure Zertifikate vollautomatisch erstellen oder erneuern lassen. Dabei muss einmalig folgender Befehl ausgeführt werden:
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/.credentials/cloudflare.ini -d linuxpirat.de
Nach erfolgreicher Erstellung oder Verlängerung erhaltet ihr wieder wie folgt eine Bestätigung
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
...
Sollte das Zertifikat noch nicht erkannt worden sein, installiert das Zertifikat erneut.
root@linuxpirat:/etc/nginx/sites-available # certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: linuxpirat.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/linuxpirat.de.conf)
What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the certificate (may be subject to CA rate limits)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Keeping the existing certificate
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/linuxpirat.de
Traffic on port 80 already redirecting to ssl in /etc/nginx/sites-enabled/linuxpirat.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://linuxpirat.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -