SSL automático con Certbot y systemd timers

Renovación sin cron, recarga de Nginx con hooks y alertas cuando algo falla.

Candado sobre un teclado
Contenido
  1. Emitir el certificado
  2. El timer de systemd
  3. Recargar Nginx tras renovar
  4. Alertas cuando falla
  5. Verificar
  6. Repositorio y recursos

Los certificados de Let's Encrypt duran 90 días. Certbot ya trae un timer de systemd, pero conviene revisarlo, agregar el hook de recarga y enterarse cuando falle.

Emitir el certificado

terminalbash
$ sudo apt install certbot python3-certbot-nginx
$ sudo certbot --nginx -d klog.dev -d www.klog.dev

El timer de systemd

terminalbash
$ systemctl list-timers certbot.timer
NEXT                        LEFT     UNIT
Sat 2026-10-21 21:12:00 CST 12h left certbot.timer

Si tu distribución no lo trae, créalo:

configuraciónini
# /etc/systemd/system/certbot.timer
[Unit]
Description=Renovación de certificados dos veces al día

[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

Recargar Nginx tras renovar

terminalbash
#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
nginx -t && systemctl reload nginx

Nota: los hooks en deploy/ solo se ejecutan cuando un certificado realmente se renovó.

Alertas cuando falla

configuraciónini
# systemctl edit certbot.service
[Unit]
OnFailure=notify-failure@%n.service

Verificar

terminalbash
$ sudo certbot renew --dry-run
# all simulated renewals succeeded

Repositorio y recursos