Installer un certificat Let's Encrypt avec Certbot sur Linux (Ubuntu, Debian, AlmaLinux)

Tutoriels Linux › Sécurité

Documentation / Tutoriels Linux / Sécurité / Installer un certificat Let's Encrypt avec Certbot sur Linux (Ubuntu, Debian, AlmaLinux)
Mis à jour le 08/10/2026
766 vues
Débutant
20 minutes

Prérequis

  • Un serveur sous Ubuntu, Debian, AlmaLinux, Rocky, CentOS, Fedora, Alpine ou openSUSE : voir nos VPS au Canada
  • Une connexion SSH ouverte en root : Se connecter en SSH à votre VPS
  • Un nom de domaine dont l'enregistrement A pointe sur l'adresse IP du serveur (dans ce guide : votredomaine.com, à remplacer)
  • Une adresse courriel pour votre compte Let's Encrypt
Votre serveur :

Let's Encrypt délivre gratuitement des certificats HTTPS reconnus par tous les navigateurs, valables 90 jours et renouvelés sans intervention. Certbot est l'outil qui les demande, les installe dans Nginx et les renouvelle. Ce guide part de zéro : un serveur Nginx pour votre domaine, le pare-feu, Certbot, le certificat avec redirection de HTTP vers HTTPS, puis le renouvellement automatique. Choisissez votre système plus haut.

1Mettre à jour le système

Mettre à jour le système
apt update && apt upgrade -y
Résultat attendu
...
212 upgraded, 8 newly installed, 0 to remove and 4 not upgraded.
(les nombres dépendent de l'âge de l'image)
Mettre à jour le système
dnf upgrade -y
Résultat attendu
...
Complete!
Mettre à jour le système
dnf upgrade -y
Résultat attendu
...
Complete!
Mettre à jour le système, puis redémarrer
apk update && apk upgrade && reboot
Résultat attendu
...
OK: 158 MiB in 209 packages
(les nombres dépendent de l'image ; la connexion SSH se coupe au redémarrage)

Alpine redémarre après la mise à jour : quand elle remplace le noyau, les modules du noyau en cours disparaissent et le pare-feu de l'étape 4 ne peut plus se charger (« Couldn't determine iptables version »). Reconnectez-vous en SSH après une minute.

Mettre à jour le système
zypper -n refresh && zypper -n update
Résultat attendu
All repositories have been refreshed.
...

2Installer Nginx

Certbot a besoin d'un serveur web qui répond pour votre domaine : Let's Encrypt vérifie que vous contrôlez le domaine en interrogeant le port 80. Nginx sert aussi de serveur pour votre site ; si vous en avez déjà un, passez cette étape.

Installer Nginx (le service démarre tout de suite)
apt install -y nginx
Installer Nginx et démarrer le service
dnf install -y nginx && systemctl enable --now nginx
Installer Nginx et démarrer le service
dnf install -y nginx && systemctl enable --now nginx
Installer Nginx et démarrer le service
apk add nginx && rc-update add nginx default && service nginx start
Installer Nginx et démarrer le service
zypper -n install nginx && systemctl enable --now nginx
Vérifier la version
nginx -v
Résultat attendu
nginx version: nginx/1.24.0 (Ubuntu)
Vérifier la version
nginx -v
Résultat attendu
nginx version: nginx/1.20.1
Vérifier la version
nginx -v
Résultat attendu
nginx version: nginx/1.30.4
Vérifier la version
nginx -v
Résultat attendu
nginx version: nginx/1.30.4
Vérifier la version
nginx -v
Résultat attendu
nginx version: nginx/1.27.2

3Déclarer votre domaine dans Nginx

Un dossier pour les fichiers du site, une page d'accueil, et un fichier de configuration qui dit à Nginx de servir ce dossier pour votre domaine. Certbot lira ce fichier pour y ajouter le certificat. Remplacez votredomaine.com par votre domaine, dans les trois boîtes.

Créer le dossier du site et une page d'accueil
mkdir -p /var/www/votredomaine.com && echo '<h1>Bonjour depuis votredomaine.com</h1>' > /var/www/votredomaine.com/index.html
Ubuntu / DebianCréer la configuration du site
cat > /etc/nginx/conf.d/votredomaine.com.conf << 'EOF'
server {
    listen 80;
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
}
EOF
AlmaLinux / Rocky / CentOSCréer la configuration du site
cat > /etc/nginx/conf.d/votredomaine.com.conf << 'EOF'
server {
    listen 80;
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
}
EOF
FedoraCréer la configuration du site
cat > /etc/nginx/conf.d/votredomaine.com.conf << 'EOF'
server {
    listen 80;
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
}
EOF
AlpineCréer la configuration du site
cat > /etc/nginx/http.d/votredomaine.com.conf << 'EOF'
server {
    listen 80;
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
}
EOF
openSUSECréer la configuration du site
cat > /etc/nginx/vhosts.d/votredomaine.com.conf << 'EOF'
server {
    listen 80;
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
}
EOF

SELinux refuse à Nginx de lire un dossier créé à la main sous /var/www tant qu'il n'a pas l'étiquette des contenus web : restorecon la pose.

Donner au dossier l'étiquette SELinux des contenus web
restorecon -R /var/www
Vérifier la configuration et recharger Nginx
nginx -t && systemctl reload nginx
Résultat attendu
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Vérifier la configuration et recharger Nginx
nginx -t && systemctl reload nginx
Résultat attendu
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Vérifier la configuration et recharger Nginx
nginx -t && systemctl reload nginx
Résultat attendu
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Vérifier la configuration et recharger Nginx
nginx -t && systemctl reload nginx
Résultat attendu
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Vérifier la configuration et recharger Nginx
nginx -t && rc-service nginx reload
Résultat attendu
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Vérifier : Nginx sert la page pour votre domaine
curl -s -H 'Host: votredomaine.com' http://127.0.0.1/
Résultat attendu
<h1>Bonjour depuis votredomaine.com</h1>

4Ouvrir les ports 80 et 443 dans le pare-feu

Le port 80 sert à la vérification de Let's Encrypt et à la redirection vers HTTPS, le port 443 au site en HTTPS.

Activer le pare-feu (SSH reste autorisé) et ouvrir les ports web
apt install -y ufw && ufw allow 22/tcp && ufw allow 80/tcp && ufw allow 443/tcp && ufw --force enable
Résultat attendu
...
Firewall is active and enabled on system startup
Activer le pare-feu (SSH reste autorisé) et ouvrir les ports web
dnf install -y firewalld && systemctl enable --now firewalld && firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload
Résultat attendu
...
success
success
Activer le pare-feu (SSH reste autorisé) et ouvrir les ports web
dnf install -y firewalld && systemctl enable --now firewalld && firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload
Résultat attendu
...
success
success
Activer le pare-feu (SSH reste autorisé) et ouvrir les ports web
apk add ufw && ufw allow 22/tcp && ufw allow 80/tcp && ufw allow 443/tcp && ufw --force enable && rc-update add ufw default
Résultat attendu
...
Firewall is active and enabled on system startup
 * service ufw added to runlevel default
Ouvrir les ports web (firewalld est déjà actif sur openSUSE)
firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload
Résultat attendu
success
success

5Installer Certbot et son greffon Nginx

Le greffon Nginx permet à Certbot de prouver le domaine à travers Nginx, sans l'arrêter, puis d'écrire lui-même les lignes HTTPS dans la configuration du site.

Installer Certbot et le greffon Nginx
apt install -y certbot python3-certbot-nginx
Installer Certbot et le greffon Nginx (dépôt EPEL)
dnf install -y epel-release && dnf install -y certbot python3-certbot-nginx
Installer Certbot et le greffon Nginx
dnf install -y certbot python3-certbot-nginx python3-pyparsing
Installer Certbot et le greffon Nginx
apk add certbot certbot-nginx
Installer Certbot et le greffon Nginx
zypper -n install python313-certbot-nginx
Vérifier la version
certbot --version
Résultat attendu
certbot 2.9.0
Vérifier la version
certbot --version
Résultat attendu
certbot 3.1.0
Vérifier la version
certbot --version
Résultat attendu
certbot 5.7.0
Vérifier la version
certbot --version
Résultat attendu
certbot 5.6.0
Vérifier la version
certbot --version
Résultat attendu
certbot 5.1.0

6Obtenir le certificat

Une seule commande : Certbot crée votre compte Let's Encrypt avec votre adresse courriel, demande le certificat pour le domaine, l'installe dans la configuration du site et ajoute la redirection de HTTP vers HTTPS.

Demander et installer le certificat (remplacez le domaine et l'adresse courriel)
certbot --nginx -d votredomaine.com --non-interactive --agree-tos -m vous@votredomaine.com --redirect
Résultat attendu
Account registered.
Requesting a certificate for votredomaine.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/votredomaine.com/privkey.pem
This certificate expires on 2026-12-16.
...
Successfully deployed certificate for votredomaine.com to /etc/nginx/conf.d/votredomaine.com.conf
Congratulations! You have successfully enabled HTTPS on https://votredomaine.com
Demander et installer le certificat (remplacez le domaine et l'adresse courriel)
certbot --nginx -d votredomaine.com --non-interactive --agree-tos -m vous@votredomaine.com --redirect
Résultat attendu
Account registered.
Requesting a certificate for votredomaine.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/votredomaine.com/privkey.pem
This certificate expires on 2026-12-16.
...
Successfully deployed certificate for votredomaine.com to /etc/nginx/conf.d/votredomaine.com.conf
Congratulations! You have successfully enabled HTTPS on https://votredomaine.com
Demander et installer le certificat (remplacez le domaine et l'adresse courriel)
certbot --nginx -d votredomaine.com --non-interactive --agree-tos -m vous@votredomaine.com --redirect
Résultat attendu
Account registered.
Requesting a certificate for votredomaine.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/votredomaine.com/privkey.pem
This certificate expires on 2026-12-16.
...
Successfully deployed certificate for votredomaine.com to /etc/nginx/conf.d/votredomaine.com.conf
Congratulations! You have successfully enabled HTTPS on https://votredomaine.com
Demander et installer le certificat (remplacez le domaine et l'adresse courriel)
certbot --nginx -d votredomaine.com --non-interactive --agree-tos -m vous@votredomaine.com --redirect
Résultat attendu
Account registered.
Requesting a certificate for votredomaine.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/votredomaine.com/privkey.pem
This certificate expires on 2026-12-16.
...
Successfully deployed certificate for votredomaine.com to /etc/nginx/http.d/votredomaine.com.conf
Congratulations! You have successfully enabled HTTPS on https://votredomaine.com
Demander et installer le certificat (remplacez le domaine et l'adresse courriel)
certbot --nginx -d votredomaine.com --non-interactive --agree-tos -m vous@votredomaine.com --redirect
Résultat attendu
Account registered.
Requesting a certificate for votredomaine.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/votredomaine.com/privkey.pem
This certificate expires on 2026-12-16.
...
Successfully deployed certificate for votredomaine.com to /etc/nginx/vhosts.d/votredomaine.com.conf
Congratulations! You have successfully enabled HTTPS on https://votredomaine.com

Certbot a réécrit le fichier du site : le bloc d'origine écoute maintenant en 443 avec le certificat, et un second bloc renvoie le port 80 vers HTTPS. Les lignes qu'il a ajoutées portent « managed by Certbot ».

Voir la configuration après Certbot
cat /etc/nginx/conf.d/votredomaine.com.conf
Résultat attendu
server {
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = votredomaine.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name votredomaine.com;
    return 404; # managed by Certbot
}
Voir la configuration après Certbot
cat /etc/nginx/conf.d/votredomaine.com.conf
Résultat attendu
server {
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = votredomaine.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name votredomaine.com;
    return 404; # managed by Certbot
}
Voir la configuration après Certbot
cat /etc/nginx/conf.d/votredomaine.com.conf
Résultat attendu
server {
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = votredomaine.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name votredomaine.com;
    return 404; # managed by Certbot
}
Voir la configuration après Certbot
cat /etc/nginx/http.d/votredomaine.com.conf
Résultat attendu
server {
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = votredomaine.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name votredomaine.com;
    return 404; # managed by Certbot
}
Voir la configuration après Certbot
cat /etc/nginx/vhosts.d/votredomaine.com.conf
Résultat attendu
server {
    server_name votredomaine.com;
    root /var/www/votredomaine.com;
    index index.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/votredomaine.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/votredomaine.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = votredomaine.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name votredomaine.com;
    return 404; # managed by Certbot
}

7Vérifier le site en HTTPS

Le site répond en HTTPS
curl -sI https://votredomaine.com/ | head -1
Résultat attendu
HTTP/1.1 200 OK
HTTP redirige vers HTTPS
curl -sI http://votredomaine.com/ | head -1
Résultat attendu
HTTP/1.1 301 Moved Permanently
Le certificat installé et sa date d'expiration
certbot certificates
Résultat attendu
Found the following certs:
  Certificate Name: votredomaine.com
    Serial Number: 6f8738e86c87c899fa649f56e0ff9d4cce1
    Key Type: ECDSA
    Domains: votredomaine.com
    Expiry Date: 2026-12-16 14:48:50+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/votredomaine.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/votredomaine.com/privkey.pem

Dans le navigateur, https://votredomaine.com affiche le cadenas ; le certificat est émis par Let's Encrypt et valable 90 jours.

8Renouvellement automatique

Certbot renouvelle un certificat quand il lui reste moins de 30 jours, à condition qu'une tâche planifiée le lance chaque jour.

Vérifier la minuterie installée par le paquet
systemctl list-timers | grep certbot
Résultat attendu
Fri 2026-09-18 08:46:21 UTC    16h -    - certbot.timer    certbot.service
Activer la minuterie de renouvellement
systemctl enable --now certbot-renew.timer && systemctl list-timers | grep certbot
Résultat attendu
Fri 2026-09-18 00:26:28 UTC 8h left    -    - certbot-renew.timer    certbot-renew.service
Activer la minuterie de renouvellement
systemctl enable --now certbot-renew.timer && systemctl list-timers | grep certbot
Résultat attendu
Fri 2026-09-18 06:20:54 UTC    14h -    - certbot-renew.timer    certbot-renew.service
Démarrer cron et programmer le renouvellement chaque nuit à 3 h
rc-update add crond default && service crond start && (crontab -l 2>/dev/null; echo "0 3 * * * certbot renew --quiet") | crontab - && crontab -l
Résultat attendu
...
0 3 * * * certbot renew --quiet
Installer cron et programmer le renouvellement chaque nuit à 3 h
zypper -n install cronie && systemctl enable --now cron && (crontab -l 2>/dev/null; echo "0 3 * * * certbot renew --quiet") | crontab - && crontab -l
Résultat attendu
...
0 3 * * * certbot renew --quiet
Tester le renouvellement à blanc (rien n'est changé)
certbot renew --dry-run
Résultat attendu
...
Congratulations, all simulated renewals succeeded:
  /etc/letsencrypt/live/votredomaine.com/fullchain.pem (success)

Après un renouvellement, le greffon Nginx recharge Nginx lui-même : le nouveau certificat est servi sans intervention.

HTTPS en place

Votre site répond en HTTPS avec un certificat Let's Encrypt, HTTP y renvoie, et le renouvellement tourne seul. Pour un serveur web complet avec PHP, voyez Installer Nginx avec PHP-FPM.

Erreurs fréquentes

💬 Écrivez-nous sur Messenger !