Skip to content

Let's Encrypt installieren

Verschoben Let's Encrypt
3 1 1.4k
  • Was ist Let's Encrypt?

    Let’s Encrypt (deutsch „Lasst uns verschlüsseln“) ist eine Zertifizierungsstelle, die Ende 2015 in Betrieb gegangen ist und kostenlose X.509-Zertifikate für Transport Layer Security (TLS) anbietet. Dabei ersetzt ein automatisierter Prozess die bisher gängigen komplexen händischen Vorgänge bei der Erstellung, Validierung, Signierung, Einrichtung und Erneuerung von Zertifikaten für verschlüsselte Websites.

    Quelle: de.wikipedia.org

    Ziel des Ganzen ist es, den Datentransport zwischen dem Client und dem Webserver zu verschlüsseln, so das unterwegs niemand die Daten mitlesen kann.

    Vorbereitung

    Bei meinem Serverumzug ist folgendes aufgefallen.

     Sep 29 14:22:27 amadeus nginx[1078]: nginx: [emerg] BIO_new_file("/etc/nginx/dhparams.pem") failed (SSL: error:02001002:system
    

    Nginx meckert über einen nicht vorhanden Schlüssel. Hmm, etwas googlen und fündig geworden.

    Man muss mittels openssl erstmal einen geheimen privaten Key erzeugen.

    root@amadeus /etc/letsencrypt # openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
    Generating DH parameters, 2048 bit long safe prime, generator 2
    This is going to take a long time
    ...........................................................................+...................................................................
    (gekürzt)
    

    Das erzeugt im angegebenen Verzeichnis einen 2048 Bit langen Schlüssel. Ganz ängstliche wählen 4096 Bit. Mit der Option "-aes256" kann man den Key auch noch mit einem Passwort verschlüsseln.

    Das File in den Ordner /etc/nginx kopieren und fertig. Ich habe da noch ein kleines Problem, das in der Konfiguration das File dhparams.pem heißt, das erzeugte File aber dhparam.pem. Vermutlich ein Tippfehler von mir, schau ich mir nochmal an. Vorerst habe ich die Datei einfach umbenannt.

    Installation

    Nach dem Hinweis meines Sysadmins 🙂 muss ich das hier noch ein wenig verfeinern.

    apt install letsencrypt
    

    Danach

    root@one /opt/letsencrypt # /etc/init.d/nginx stop
    [ ok ] Stopping nginx (via systemctl): nginx.service.
    root@one /opt/letsencrypt # letsencrypt certonly --standalone -d frank-mankel.org -d www.frank-mankel.org
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Plugins selected: Authenticator standalone, Installer None
    Obtaining a new certificate
    Performing the following challenges:
    http-01 challenge for frank-mankel.org
    http-01 challenge for www.frank-mankel.org
    Waiting for verification...
    Cleaning up challenges
    
    IMPORTANT NOTES:
     - Congratulations! Your certificate and chain have been saved at:
       /etc/letsencrypt/live/frank-mankel.org/fullchain.pem
       Your key file has been saved at:
       /etc/letsencrypt/live/frank-mankel.org/privkey.pem
       Your cert will expire on 2018-07-13. To obtain a new or tweaked
       version of this certificate in the future, simply run
       letsencrypt-auto again. To non-interactively renew *all* of your
       certificates, run "letsencrypt-auto 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
    

    Das hat schon mal geklappt!!

    Hinweis

    Der Certbot kann je nach System entweder

    certbot-auto
    

    oder

    certbot
    

    heißen. Quelle: https://certbot.eff.org/docs/intro.html#installation

    Hier liegen die Zertifikate

    /etc/letsencrypt/live/frank-mankel.org
    

    Dort liegen jetzt folgende Files:

    root@one /etc/letsencrypt/live/frank-mankel.org # ls -l
    total 4
    lrwxrwxrwx 1 root root  40 Apr 14 15:15 cert.pem -> ../../archive/frank-mankel.org/cert1.pem
    lrwxrwxrwx 1 root root  41 Apr 14 15:15 chain.pem -> ../../archive/frank-mankel.org/chain1.pem
    lrwxrwxrwx 1 root root  45 Apr 14 15:15 fullchain.pem -> ../../archive/frank-mankel.org/fullchain1.pem
    lrwxrwxrwx 1 root root  43 Apr 14 15:15 privkey.pem -> ../../archive/frank-mankel.org/privkey1.pem
    -rw-r--r-- 1 root root 543 Apr 14 15:15 README
    

    Zertifikate in nginx einbauen

    nginx stoppen:

    /etc/init.d/nginx stop
    

    Meine alte nginx Datei OHNE https. Datei default

    server {
    if ($host != 'frank-mankel.org' ) {
    rewrite ^/(.*)$ http://frank-mankel.org/$1 permanent;
    }
    
        listen 80;
    
        server_name frank-mankel.org;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    NEUE Datei mit https!!

    ### redirects http requests to https
    
    server {
        server_name  www.frank-mankel.org;
        rewrite ^(.*) http://frank-mankel.org$1 permanent;
    }
    
    
    
    server {
        listen 80;
        server_name frank-mankel.org;
        return 302 https://$server_name$request_uri;
    }
    
    ### the https server
    server {
        # listen on ssl, deliver with speedy if possible
        listen 443 ssl spdy;
    
        server_name frank-mankel.org;
    
    
        # change these paths!
        ssl_certificate /etc/letsencrypt/live/frank-mankel.org/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/frank-mankel.org/privkey.pem;
    
        # enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    
        # disables all weak ciphers
        ssl_ciphers 'AES128+EECDH:AES128+EDH';
    
        ssl_prefer_server_ciphers on;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567;  # no trailing slash
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    Der Ganze http Verkehr wird nach https umgeleitet.

    Als allererstes strippen wir www aus dem Namen.

    if ($host != 'frank-mankel.org' ) {
     rewrite ^/(.*)$ http://frank-mankel.org/$1 permanent;
    }
    

    Der Rest entspricht der nginx Doku!

    Jetzt bauen wir das Zertifikat ein. Pfade anpassen.

    # change these paths!
        ssl_certificate /etc/letsencrypt/live/frank-mankel.org/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/frank-mankel.org/privkey.pem;
    

    Danach speichern und nginx wieder starten

    /etc/init.d/nginx start  
    

    Alles Testen und schauen ob alles funktioniert.

    Zertifikat erneuern

    Das Let's Encrypt Zertifikat läuft nur 90 Tage, danach muss es erneuert werden!

    Also legen wir uns einen crontab an

    crontab -e
    

    Wir fügen folgende Zeile hinzu.

     * 3  1 * * certbot -q renew
    

    Das war mein erster Versuch, das gibt aber einen Fehler. So lange nginx läuft, geht das nicht. Aber dafür kann man dem certbot Befehle mitgeben um nginx zu stoppen und zu starten. Das sieht dann so aus.

    * 3  1 * * certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"
    

    Eine erfolgreiche Zertifikatsverlängerung sieht dann so aus.

    certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    
    -------------------------------------------------------------------------------
    Processing /etc/letsencrypt/renewal/frank-mankel.org.conf
    -------------------------------------------------------------------------------
    Attempting to parse the version 0.23.0 renewal configuration file found at /etc/letsencrypt/renewal/frank-mankel.org.conf with version 0.10.2 of Certbot. This might not work.
    Cert is due for renewal, auto-renewing...
    Running pre-hook command: service nginx stop
    Renewing an existing certificate
    Performing the following challenges:
    tls-sni-01 challenge for frank-mankel.org
    tls-sni-01 challenge for www.frank-mankel.org
    Waiting for verification...
    Cleaning up challenges
    Generating key (2048 bits): /etc/letsencrypt/keys/0004_key-certbot.pem
    Creating CSR: /etc/letsencrypt/csr/0004_csr-certbot.pem
    
    -------------------------------------------------------------------------------
    new certificate deployed without reload, fullchain is
    /etc/letsencrypt/live/frank-mankel.org/fullchain.pem
    -------------------------------------------------------------------------------
    
    Congratulations, all renewals succeeded. The following certs have been renewed:
      /etc/letsencrypt/live/frank-mankel.org/fullchain.pem (success)
    Running post-hook command: service nginx start
    

    Erledigt 🙂

    Vielen Dank für eine tolle Anleitung zum Thema! Quelle: https://willy-tech.de/ssl-zertifikat-mit-lets-encrypt-erstellen/

  • Ich will das Ganze um eine Subdomain erweitern

    root@one /opt/letsencrypt # letsencrypt certonly --standalone -d frank-mankel.org -d www.frank-mankel.org -d forum.frank-mankel.org 
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Plugins selected: Authenticator standalone, Installer None
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    You have an existing certificate that contains a portion of the domains you
    requested (ref: /etc/letsencrypt/renewal/frank-mankel.org.conf)
    
    It contains these names: frank-mankel.org, www.frank-mankel.org
    
    You requested these names for the new certificate: frank-mankel.org,
    www.frank-mankel.org, forum.frank-mankel.org.
    
    Do you want to expand and replace this existing certificate with the new
    certificate?
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (E)xpand/(C)ancel: E
    Renewing an existing certificate
    Performing the following challenges:
    http-01 challenge for forum.frank-mankel.org
    tls-sni-01 challenge for frank-mankel.org
    tls-sni-01 challenge for www.frank-mankel.org
    Waiting for verification...
    Cleaning up challenges
    
    IMPORTANT NOTES:
     - Congratulations! Your certificate and chain have been saved at:
       /etc/letsencrypt/live/frank-mankel.org/fullchain.pem
       Your key file has been saved at:
       /etc/letsencrypt/live/frank-mankel.org/privkey.pem
       Your cert will expire on 2018-10-17. To obtain a new or tweaked
       version of this certificate in the future, simply run
       letsencrypt-auto again. To non-interactively renew *all* of your
       certificates, run "letsencrypt-auto 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
    
  • Wenn ihr alles richtig gemacht habt, dann könnt ihr Euer Zertifikat überprüfen lassen. Sollte dann so aussehen.

    0_1538314120455_index.jpeg

  • FrankMF FrankM hat am auf dieses Thema verwiesen
  • Give back to open source 2023

    Allgemeine Diskussionen linux opensource
    1
    0 Stimmen
    1 Beiträge
    144 Aufrufe
    Niemand hat geantwortet
  • Wichtige Links

    Angeheftet Ansible ansible linux
    1
    0 Stimmen
    1 Beiträge
    155 Aufrufe
    Niemand hat geantwortet
  • FrOSCon 18 - Bericht

    Linux froscon linux
    2
    1
    0 Stimmen
    2 Beiträge
    636 Aufrufe
    FrankMF
    Und man soll ja auch was mitnehmen.... [image: 1691603320257-screenshot_20230809_194620.png] Das ist Semaphore, installiert in einer VM auf meinem Proxmox.
  • PHP Webseite lokal einhängen mit sshfs

    PHP php linux
    1
    2
    0 Stimmen
    1 Beiträge
    95 Aufrufe
    Niemand hat geantwortet
  • KDE Plasma setzt auf Wayland

    Linux kde linux
    1
    0 Stimmen
    1 Beiträge
    98 Aufrufe
    Niemand hat geantwortet
  • Portainer - NodeBB Container erstellen

    Linux nodebb portainer linux redis
    1
    5
    0 Stimmen
    1 Beiträge
    346 Aufrufe
    Niemand hat geantwortet
  • Mobian - vollverschlüsselt

    Software pinephone mobian linux
    1
    0 Stimmen
    1 Beiträge
    343 Aufrufe
    Niemand hat geantwortet
  • Debian Buster 10 Release

    Linux linux nvidia
    3
    1
    0 Stimmen
    3 Beiträge
    464 Aufrufe
    FrankMF
    Da man ja beim Login auswählen kann, mit was die Session startet, war ich doch jetzt etwas neugierig was überhaupt läuft. [image: 1562484643462-img_20190707_092217.jpg] frank@debian:~$ echo $WAYLAND_DISPLAY frank@debian:~$ loginctl SESSION UID USER SEAT TTY 7 1000 frank seat0 tty2 c1 116 Debian-gdm seat0 tty1 2 sessions listed. frank@debian:~$ loginctl show-session c1 -p Type Type=x11 frank@debian:~$ loginctl show-session c1 Id=c1 User=116 Name=Debian-gdm Timestamp=Sat 2019-07-06 22:43:34 CEST TimestampMonotonic=30094837 VTNr=1 Seat=seat0 TTY=tty1 Remote=no Service=gdm-launch-environment Scope=session-c1.scope Leader=1015 Audit=4294967295 Type=x11 Class=greeter Active=no State=online IdleHint=yes IdleSinceHint=1562446130937731 IdleSinceHintMonotonic=346278596 LockedHint=yes Die Installation der Nvidia Treiber macht da wohl einen x11 Desktop raus. Aber auch nicht weiter schlimm, der Wayland lief ja hier überhaupt nicht. Würde mich aber über interessante Links zum Thema freuen