certbot,

Certbot auto renew SSL/TLS certificate with a cron job

Jan 19, 2022 · 1 min read · Post a comment

If you are using a free SSL/TLS certificate from Certbot, probably you are tired of the manual renewal. Here I’m going to show you how to automate the process of creating a cron job that will automatically renew the expired certificates.

Prerequisites

  • Certbot
  • Debian-based distro

Solution

Step 1. Navigate to the /etc/cron.d directory.

cd /etc/cron.d/

Step 2. Create a new file called certbot.

touch certbot

Step 3. Open the Certbot file and paste the following config:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 0 * * * /usr/bin/certbot renew && systemctl restart nginx

Note: Confirm the Certbot binary path by running which certbot. Mostly, Certbot could be found under: /usr/bin/certbot or /usr/local/bin/certbot.

Step 4. Restart the cron service.

systemctl restart cron

Conclusion

Now, this cron job will check if some certificates are expired it will renew it automatically. In the next topic you will see how to renew it on RHEL-based distros. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.