Skip to content

Instantly share code, notes, and snippets.

@EduardoSP6
Last active October 7, 2025 23:22
Show Gist options
  • Select an option

  • Save EduardoSP6/6f3bc5fe92dd128a7e4edf597adf2116 to your computer and use it in GitHub Desktop.

Select an option

Save EduardoSP6/6f3bc5fe92dd128a7e4edf597adf2116 to your computer and use it in GitHub Desktop.

Como habilitar a auto renovação dos certificados SSL letsencrypt:

Sistema: Ubuntu 18.04 LTS (bionic) Web Server: Nginx

De acordo com as intruções do site: https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx.html Os pacotes Certbot no seu sistema vêm com uma tarefa cron ou timer do systemd que renovará seus certificados automaticamente antes que eles expirem. Você não precisará executar o Certbot novamente, a menos que altere sua configuração. Você pode testar a renovação automática de seus certificados executando este comando:

sudo certbot renew --dry-run
  • O comando para renovar o certbot é instalado em um dos seguintes locais:
/etc/crontab/
/etc/cron.*/*
systemctl list-timers
  • No meu caso ele instalou em /etc/cron.d/. Contendo:
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew
  • Execute os comandos abaixo para habilitar:
systemctl enable certbot.timer
systemctl start certbot.timer
  • Agora execute o comando abaixo e verifique na lista se o timer está programado para executar:
systemctl list-timers --all

O cronômetro do certbot deve estar aqui /lib/systemd/system/certbot.timer e executará o comando especificado em: /lib/systemd/system/certbot.service

O certbot.timer executará o certbot.service de 12h em 12h.

# cat /lib/systemd/system/certbot.timer
[Unit]
Description=Run certbot twice daily

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

[Install]
WantedBy=timers.target

E certbot.service executará o comando renew.

# cat /lib/systemd/system/certbot.service
[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://letsencrypt.readthedocs.io/en/latest/
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew
PrivateTmp=true

====================================================================================== Referências:

https://serverfault.com/questions/790772/cron-job-for-lets-encrypt-renewal https://community.letsencrypt.org/t/cerbot-cron-job/23895/5 https://certbot.eff.org/docs/using.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment