Kostenloses Apache Webserver Zertifikat mit Let’s Encrypt Certbot + Auto Cert renew Script

Du möchtest auf deiner Website mit Apache als Webserver ein kostenloses SSL Zertifikat installieren? Dann bist du hier genau richtig! Wir zeigen dir, wie du solch ein SSL Zertifikat kostenlos mit Hilfe des Let’s Encrypt Certbots einrichtest. Außerdem kannst du hier erfahren, wie du ein automatisches „Cert renew“ Script ausführen lassen kannst, dass deine Zertifikate immer aktuell hält.

undraw secure login pdn4

Die Domain, für die das SSL Zertifikat eingerichtet werden soll muss aus dem Internet erreichbar sein, da Certbot sonst nicht die Domain verifizieren kann.

Apache Certbot installieren

Installiere als erstes das „python-certbot-apache“ Paket.

sudo apt install certbot python3-certbot-apache -y 

Apache Certbot Cert Wizard Command ausführen

Mit diesem Command kannst du den Apache Certbot Cert Wizard ausführen, der dir alle deine Apache configs auflistet und dich durch die Zertifikatsinstallation führt.

certbot --apache 

Wenn du Certbot zum ersten mal ausführst, musst du noch folgende Sachen angeben. Die Mail dient dazu, dir Nachrichten zu ablaufenden Zertifikaten zu senden.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mail@deinedomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: <Deine Antwort> 

Cert Wizard durchgehen

Gehe den Cert Wizard wie folgt durch.

root@[...]:~ certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[...]
1: testssl.[...]
[...]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1 

Gebe hier die Nummer ein, die in der Liste oberhalb vor der gewünschten Domain steht.

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for testssl.[...]
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/[...]-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/[...]-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/[...]-le-ssl.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 

Hier kannst du entscheiden, ob Certbot eine Weiterleitung von HTTP auf HTTPS einrichten soll. Wir wählen hier „2“, da wir einen Redirect einrichten wollen.

Redirecting vhost in /etc/apache2/sites-enabled/[...].conf to ssl vhost in /etc/apache2/sites-available/[...]-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://testssl.[...]
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=testssl.[...]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/testssl.[...]/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/testssl.[...]/privkey.pem
   Your cert will expire on 2021-04-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. 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
root@[...]:~ 

Wenn die Nachricht „Congratulations! You have successfully […]“ erscheint, hast du erfolgreich das SSL Zertifikat installiert.

Auto Renew Script anlegen (optional)

Falls du dir den Output des obrigen Vorgangs aufmerksam durchgelesen hast, hast du bestimmt gesehen, dass dort folgende Bemerkung stand.

[...] Your cert will expire on 2021-04-11. [...] 

Um das unbemerkte ablaufen deines Zertifikats zu verhindern, empfehlen wir dir ein selbst startendes „Cert renew Script“ laufen zu lassen. Rufe die „crontab“ Datei mit folgendem Command auf.

Wenn du Crontab das erste mal verwendest, wähle nach dem abschicken des Commands „crontab -e“ „1“ um nano als Editor zu verwenden.

crontab -e 
no crontab for root - using an empty one
Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.tiny
  3. /bin/ed
Choose 1-3 [1]: 1 

Gehe an das Ende von Crontab und füge folgende Zeile ein.

1 0 * * * certbot renew --post-hook "systemctl restart apache2" 

Damit wird jede Nacht um 1 Uhr der Command „certbot renew“ ausgeführt und Apache neu gestartet.

Fertig!

Zufrieden? Dann schreib gerne einen Kommentar.

Diesen Beitrag teilen:

4 Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben