[24] Rocky Linux 9 – Certyfikat SSL – Let’s Encrypt

15 stycznia 2025 Wyłączono przez Adam [zicherka] Nogły

Przykład opisany w tym rozdziale dotyczy domeny [vrl01.zicher.net], a nie tak jak w opisach w całej witrynie – vrl01.zicher.lab. Albowiem dostęp do rejestracji domeny [.lab] jest – delikatnie mówiąc – utrudniony.

Zainstaluj teraz certyfikaty SSL/TLS od firmy Let’s Encrypt, która zapewnia bezpłatne certyfikaty SSL/TLS. Na poniższej stronie znajdują się szczegółowe informacje na temat certyfikatów SSL/TLS Let’s Encrypt.

https://letsencrypt.org/

Data ważności certyfikatu od Let’s Encrypt wynosi 90 dni, dlatego należy dokonać aktualizacji naszego certyfikatu w ciągu następnych 90 dni.

Jeśli jednak zainstalowałeś pakiet Certbot ze Snapd, skrypt Systemd Timer jest w nim zawarty, więc odnawianie certyfikatów odbywa się automatycznie.

Zainstaluj Snapd – więcej informacji na ten temat przeczytasz w rozdziale „Menadżer pakietów – Snappy”.

Zainstaluj klienta Certbot ze Snapd.

[root@vrl01 ~]# snap install certbot --classic
certbot 2.9.0 from Certbot Project (certbot-eff✓) installed
[root@vrl01 ~]# ln -s /snap/bin/certbot /usr/bin/certbot

Zdobądź certyfikaty.

Potrzebujesz pracującego serwera WWW, takiego jak Apache httpd lub Nginx, musi on być uruchomiony na serwerze, na którym pracujesz i na który chcesz pobrać certyfikaty od Let’s Encrypt.

Co więcej, wymagana jest możliwość dostępu z Internetu do działającego serwera na porcie 80 na potrzeby weryfikacji przez Let’s Encrypt.

Dla opcji [–webroot] użyj katalogu w lokalizacji webroot [/var/www/html] na swoim serwerze jako tymczasowego miejsca pracy.

# -w [katalog główny dokumentu] -d [nazwa FQDN, którą chcesz uzyskać certyfikaty]
# FQDN (w pełni kwalifikowana nazwa domeny): nazwa_hosta.nazwa_domeny

Jeśli chcesz uzyskać certyfikaty dla więcej niż 2 nazw FQDN, określ je wszystkie jak poniżej

# przykładowo jeśli chcesz uzyskać certyfikaty dla: [zicher.net] i [vrl01.zicher.net]
# [-d zicher.lab -d vrl01.zicher.lab]
[root@vrl01 ~]# certbot certonly --webroot -w /var/www/html -d vrl01.zicher.net
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@zicher.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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: y
Account registered.
Requesting a certificate for vrl01.zicher.net
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/vrl01.zicher.net/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/vrl01.zicher.net/privkey.pem
This certificate expires on 2024-06-10.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Certyfikat został wygenerowany pomyślnie, jeśli zostanie wyświetlony komunikat [Successfully received certificate]. Certyfikaty są tworzone w katalogu [/etc/letsencrypt/live/(FQDN)/]

  • pem certyfikat serwera SSL (zawiera klucz publiczny)
  • pem certyfikat pośredni
  • pem połączony plik cert.pem i chain.pem
  • pem plik klucza prywatnego

Jeśli na Twoim działającym serwerze nie jest uruchomiony żaden serwer WWW, możliwe jest uzyskanie certyfikatów za pomocą funkcji Serwera WWW Certbota. Tak czy inaczej, potrzebny jest dostęp z Internetu do działającego serwera na porcie 80 ze względu na weryfikację z Let’s Encrypt.

# dla opcji [--standalone] użyj funkcji serwera WWW Certbota
# -d [FQDN, dla której chcesz otrzymać certyfikaty]
# FQDN (w pełni kwalifikowana nazwa domeny): nazwa_hosta.nazwa_domeny

Jeśli chcesz uzyskać certyfikaty dla więcej niż 2 nazw FQDN, określ wszystkie jak poniżej. Przykładowo jeśli chcesz otrzymać certyfikat dla domen [zicher.lab] i [vftp.zicher.lab] określ je w czasie żądania certyfikatu: [-d zicher.lab -d vftp.zicher.lab].

[root@vrl01 ~]# certbot certonly --standalone -d vftp.zicher.net
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for vftp.zicher.net

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/vftp.zicher.net/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/vftp.zicher.net/privkey.pem
This certificate expires on 2024-06-10.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Aby zaktualizować istniejące certyfikaty, użyj komendy [renew].

Gdy uruchomisz komendę [renew], zaktualizowane zostaną wszystkie certyfikaty, których ważność jest krótsza niż 30 dni.

Jeśli chcesz zaktualizować certyfikaty, których ważność przekracza 30 dni, dodaj opcję [–force-renew].

Jednakże pakiet [certbot] od Snapda ma systemowy timer, więc nie trzeba go uruchamiać ręcznie.

# skrypt systemowy timera jest zawarty w pakiecie Snapd Certbot
[root@vrl01 ~]# systemctl status snap.certbot.renew.timer
  • snap.certbot.renew.timer - Timer renew for snap application certbot.renew
     Loaded: loaded (/etc/systemd/system/snap.certbot.renew.timer; enabled; preset: disabled)
     Active: active (waiting) since Tue 2024-03-12 10:58:35 CET; 46min ago
      Until: Tue 2024-03-12 10:58:35 CET; 46min ago
    Trigger: Tue 2024-03-12 13:33:00 CET; 1h 47min left
   Triggers: ● snap.certbot.renew.service
mar 12 10:58:35 vrl01.zicher.lab systemd[1]: Started Timer renew for snap application certbot.renew.

# [renew] jest uruchamiane domyślnie 2 razy dziennie
[root@vrl01 ~]# systemctl cat snap.certbot.renew.timer
# /etc/systemd/system/snap.certbot.renew.timer

[Unit]
# Auto-generated, DO NOT EDIT
Description=Timer renew for snap application certbot.renew
Requires=var-lib-snapd-snap-certbot-3643.mount
After=var-lib-snapd-snap-certbot-3643.mount
X-Snappy=yes

[Timer]
Unit=snap.certbot.renew.service
OnCalendar=*-*-* 11:14
OnCalendar=*-*-* 13:33

[Install]
WantedBy=timers.target

# aktualizacja ręczna
[root@vrl01 ~]# certbot renew

# wymuszona aktualizacja ręczna
[root@vrl01 ~]# certbot renew --force-renew

Jeśli chcesz, możesz przekonwertować certyfikaty na format PKCS12 (PFX) dla systemu Windows.

[root@vrl01 ~]# openssl pkcs12 -export -in /etc/letsencrypt/live/vrl01.zicher.net/fullchain.pem -inkey /etc/letsencrypt/live/vrl01.zicher.net/privkey.pem -out /etc/letsencrypt/live/vrl01.zicher.net/vrl01_for_iis.pfx
Enter Export Password:                 # wpisz hasło do eksportu certyfikatu
Verifying - Enter Export Password:     # wpisz ponownie hasło do eksportu certyfikatu

[root@vrl01 ~]# ll /etc/letsencrypt/live/vrl01.zicher.net/
razem 8
lrwxrwxrwx. 1 root root   40 03-12 11:47 cert.pem -> ../../archive/vrl01.zicher.net/cert2.pem
lrwxrwxrwx. 1 root root   41 03-12 11:47 chain.pem -> ../../archive/vrl01.zicher.net/chain2.pem
lrwxrwxrwx. 1 root root   45 03-12 11:47 fullchain.pem -> ../../archive/vrl01.zicher.net/fullchain2.pem
lrwxrwxrwx. 1 root root   43 03-12 11:47 privkey.pem -> ../../archive/vrl01.zicher.net/privkey2.pem
-rw-r--r--. 1 root root  692 03-12 11:06 README
-rw-------. 1 root root 3072 03-12 11:52 vrl01_for_iis.pfx