How to automatically renew Let’s Encrypt certbot certs on Ubuntu?In this tutorial we have scheduled the certbot to auto-renew Let’s Encrypt SSL certificates before they expire.
Renewal of certificates only happens if they are within 30 days of the expiry date.
A cron job manages the SSL auto-renew feature. A cron file is automatically added during the installation of Certbot and we can find it in the /etc/cron.d/certbot directory.
In case it’s not available, we need to create it.
Let’s populate the cron file with this content:
Ubuntu 18.04.6 LTS on aliyun vps
A Ubuntu system has the following cron tab files and directories:
vi /etc/cron.d/certbot
crontab
certbot-renew.sh
0 3 1 * * /ktt/crons/certbot-renew.sh &>> /ktt/crons/certbot-renew.log
&>>
& 指将标准输出和标准错误输出都重定向到certbot-renew.log文件;
> 指覆盖写入到文件;
>> 指追加写入到文件。
sudo crontab -e
0 3 1 * * /ktt/crons/certbot-renew.sh &>> /ktt/crons/certbot-renew.log
0 3 1 * * 指每个月1号3点0分执行任务
Useful links
crontab的语法规则格式(每分钟、每小时、每天、每周、每月、每年定时执行 规则)