Le mode standalone exige qu'aucun autre serveur web (http/https) ne tourne sur le serveur :
certonly --standalone --renew-by-default --rsa-key-size 4096 -t --agree-tos -m email@domaine.tld -d www.domaine.tld -d domaine.tld
#!/bin/bash cd "$(dirname $0)" . $PWD/config.ini DOMAIN=$1 if [ ! -f "/etc/letsencrypt/live/$DOMAIN/cert.pem" ] ; then /etc/init.d/apache2 stop $LETSENCRYPT_BIN certonly --standalone --renew-by-default --rsa-key-size 4096 -t --agree-tos --preferred-challenges http -m $MAINTAINER -d $DOMAIN if [ "$?" -ne "0" ] ; then echo "OOPS !! Ca a foiré pour /etc/letsencrypt/live/$domain" else echo "COOL !! Ca s'est bien passé ! Je recrée ce qu'il faut si besoin et je recharge les services qui vont bien" fi /etc/init.d/apache2 start fi
C'est par ici !
#!/bin/bash cd "$(dirname $0)" . $PWD/config.ini DATE_TODAY=$(date +'%s') cd /etc/letsencrypt/live || (echo "Can't cd to /etc/letsencrypt/live !" && exit -1) RENEW=0 for domain in * do if [ -f "$domain/cert.pem" ] ; then CERT="$domain/cert.pem" CERT_END_DATE=$(openssl x509 -in "$CERT" -noout -enddate | sed -e "s/.*=//") CERT_END_DATE_FORMAT=$(date --date="$CERT_END_DATE" --iso-8601) DATE_CERT=$(date -ud "$CERT_END_DATE" +"%s") DATE_JOURS_DIFF=$(( ( $DATE_CERT - $DATE_TODAY ) / (60*60*24) )) if [ "$1" == "check" ] ; then SANCHECK=$(openssl x509 -in "$CERT" -text|grep DNS:|sed -e "s/DNS:/ /g" -e "s/, / /g") echo $CERT_END_DATE_FORMAT" => "$SANCHECK fi if [[ $DATE_JOURS_DIFF -le $NBJOURS_RENEW ]]; then echo "########### Le certificat $domain expire dans $DATE_JOURS_DIFF jours. Alors on renouvelle..." # Read the SAN (Subject Alt Names) for this cert (Warn: this code may not be super reliable :/ ) SAN=$(openssl x509 -in "$CERT" -text|grep DNS:|sed -e "s/DNS:/-d /g" -e "s/, / /g") echo "Domaines recensés dans le certificat : $SAN" echo "C'est parti :" $LETSENCRYPT_BIN certonly --webroot -w /data/www/ --renew-by-default --rsa-key-size 4096 --preferred-challenges http -t --agree-tos -m $MAINTAINER $SAN if [ "$?" -ne "0" ] ; then echo "OOPS !! Ca a foiré pour /etc/letsencrypt/live/$domain" else echo "COOL !! Ca s'est bien passé ! Je recrée ce qu'il faut si besoin et je recharge les services qui vont bien" RENEW=1 POST_TRAITEMENT_SCRIPT=$(dirname $0)/letsencrypt_posttraitement_$domain if [ -f $POST_TRAITEMENT_SCRIPT ] ; then $POST_TRAITEMENT_SCRIPT fi fi /etc/init.d/apache2 restart fi fi done
#!/bin/bash cd "$(dirname $0)" . $PWD/config.ini DATE_TODAY=$(date +'%s') cd /etc/letsencrypt/live || (echo "Can't cd to /etc/letsencrypt/live !" && exit -1) for domain in * do if [ -f "$domain/cert.pem" ] ; then CERT="$domain/cert.pem" CERT_END_DATE=$(openssl x509 -in "$CERT" -noout -enddate | sed -e "s/.*=//") DATE_CERT=$(date -ud "$CERT_END_DATE" +"%s") DATE_JOURS_DIFF=$(( ( $DATE_CERT - $DATE_TODAY ) / (60*60*24) )) if [ "$1" == "check" ] ; then SANCHECK=$(openssl x509 -in "$CERT" -text|grep DNS:|sed -e "s/DNS:/ /g" -e "s/, / /g") echo $SANCHECK" => "$CERT_END_DATE fi if [[ $DATE_JOURS_DIFF -le $NBJOURS_RENEW ]]; then echo "########### Le certificat $domain expire dans $DATE_JOURS_DIFF jours. Alors on renouvelle..." # Read the SAN (Subject Alt Names) for this cert (Warn: this code may not be super reliable :/ ) SAN=$(openssl x509 -in "$CERT" -text|grep DNS:|sed -e "s/DNS:/-d /g" -e "s/, / /g") echo "Domaines recensés dans le certificat : $SAN" echo "C'est parti :" /etc/init.d/apache2 stop $LETSENCRYPT_BIN certonly --standalone --renew-by-default --rsa-key-size 4096 -t --agree-tos -m $MAINTAINER $SAN if [ "$?" -ne "0" ] ; then echo "OOPS !! Ca a foiré pour /etc/letsencrypt/live/$domain" else echo "COOL !! Ca s'est bien passé ! Je recrée ce qu'il faut si besoin et je recharge les services qui vont bien" POST_TRAITEMENT_SCRIPT=$HERE/letsencrypt_posttraitement_$domain if [ -f $POST_TRAITEMENT_SCRIPT ] ; then $POST_TRAITEMENT_SCRIPT fi fi /etc/init.d/apache2 start fi fi done
Pour effacer proprement un certificat (dans /etc/letsencrypt)
certbot delete
Non interactif :
certbot delete --cert-name www.domaine.tld
Par défaut, la tâche de mise à jour des certificats est lancée par un timer systemd plusieurs fois par jour. Si on a besoin de la désactiver :
systemctl stop certbot.timer systemctl disable certbot.timer
Lors de la création d'un certificat, plusieurs choses peuvent l'empécher, et c'est pas toujours évident de savoir quoi. Posez-vous les bonnes questions