1. Home
  2. Linux
  3. Apache - MySQL - PHP
  4. Let's Encrypt Zertifikate mit Certbot

Let's Encrypt Zertifikate mit Certbot

Let's Encrypt ist eine freie, automatisierte und offene Zertifizierungsstelle, welche von der ISRG (Internet Security Research Group) herausgebracht wurde. SSL Zertifikate sind heutzutage unablässig bei der Bereitstellung von Inhalten im Internet, wie zB Webseiten.

Diese Anleitung beschreibt die Installation und Konfiguration von Let's Encrypt mit Certbot auf Linux Debian 11 mit Apache Webserver.

Installation

# apt update && apt upgrade
# apt install certbot python3-certbot-apache -y

Im Grunde war es das schon. Certbot speichert seine Konfiguration in /etc/letsencrypt ab. Die Verzeichnisse und Dateien werden erst beim Ausführen des certbot-Kommandos vervollständigt:

# ls -la /etc/letsencrypt/
insgesamt 48
drwxr-xr-x  9 root root 4096 10. Aug 18:56 .
drwxr-xr-x 72 root root 4096 10. Aug 15:54 ..
drwx------  3 root root 4096 10. Aug 16:06 accounts
drwx------  3 root root 4096 10. Aug 18:56 archive
-rw-r--r--  1 root root  121 26. Mai 2018  cli.ini
drwxr-xr-x  2 root root 4096 10. Aug 18:56 csr
drwx------  2 root root 4096 10. Aug 18:56 keys
drwx------  3 root root 4096 10. Aug 18:56 live
-rw-r--r--  1 root root  952 10. Aug 18:56 options-ssl-apache.conf
drwxr-xr-x  2 root root 4096 10. Aug 18:56 renewal
drwxr-xr-x  5 root root 4096 10. Aug 16:04 renewal-hooks
-rw-r--r--  1 root root   64 10. Aug 18:56 .updated-options-ssl-apache-conf-digest.txt

Zertifikat ausstellen

Dazu muss das Routing ung ggf. NAT vom Internet auf Port 80 und Port 443 auf den Host korrekt sein, für den das Zertifikat ausgestellt werden soll:

# certbot --apache -d subdomain.domain.de
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Requesting a certificate for subdomain.domain.de
Performing the following challenges:
http-01 challenge for subdomain.domain.de
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/subdomain.domain.de-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/subdomain.domain.de-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/subdomain.domain.de-le-ssl.conf
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/subdomain.domain.de.conf to ssl vhost in /etc/apache2/sites-available/subdomain.domain.de-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://subdomain.domain.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: it@domain.de).

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/subdomain.domain.de/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/subdomain.domain.de/privkey.pem
   Your certificate will expire on 2022-11-08. 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"

Wenn certbot mit dem Apache Modul aufgerufen wurde (--apache), erledigt das Programm den Rest für Sie. Das Zertifikat wird beantragt, ausgestellt und heruntergeladen. Es werden die notwendigen Apache Module aktiviert, ein VirtualHost für den SSL Port 443 angelegt, aktiviert und ein Redirect von Port 80 auf Port 443 eingestellt.

Zertifikate erneuern

Die von Letsencrypt ausgestellten Zertifikate lassen sich selbstständig automatisiert erneuern. Zum Überprüfen ob der Erneuerungsvorgang im Prinzip funktioniert, kann eine Erneuerung von Hand mit der Option --dry-run simuliert werden:

# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/subdomain.domain.de
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Account registered.
Simulating renewal of an existing certificate for subdomain.domain.de
Performing the following challenges:
http-01 challenge for subdomain.domain.de
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/subdomain.domain.de/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/subdomain.domain.de/fullchain.pem (success)

Für die automatische Erneuerung der Zertifikate legt certbot bei der Installation einen cron Job in /etc/cron.d/certbot an, der alle 12 Stunden das renew-Kommando ausführt:

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc.  Renewal will only occur if expiration
# is within 30 days.
#
# Important Note!  This cronjob will NOT be executed if you are
# running systemd as your init system.  If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob.  For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Wie lange die installierten Zertifikate noch gültig sind, können Sie mit dem certbot certificates Kommando abfragen:

# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: subdomain.domain.de
    Serial Number: fab001d2fedfedf4523e0aef3218fa11207
    Key Type: RSA
    Domains: kb.kastner.de
    Expiry Date: 2022-11-08 15:56:09+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/subdomain.domain.de/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/subdomain.domain.de/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Loading

Updated on 10. Oktober 2022
Was this article helpful?

Related Articles