How to setup cron job for automatic Let's Encrypt renewal?
Cron is a command-line job scheduler on Unix-like systems. It allows you to run automated tasks in the background and it's especially useful for repetitive jobs.
That means it's a great tool for automatic renewal of the Let's Encrypt certificate.
In this quick tutorial, we will take a look at how to use cron to automatically renew let's encrypt certificate.
How to renew Let's Encrypt using cron?
Let's Encrypt needs to be renewed at least weekly preferably daily. Longer time periods may cause the certificate to be already expired when renewing. Official documentation recommends running the script twice a day.
The program used for renewing Let's Encrypt is called certbot. You can install certbot using the following command:
sudo apt install certbot
Then open your crontab as shown below:
crontab -e
In the crontab file, add the following line:
0 0,12 * * * certbot renew --post-hook "systemctl reload nginx"
This will renew Let's encrypt twice a day at midnight and midday. The second
part of the command which is highlighted is used to restart the Nginx web server
after renewal. If you are using Apache, change the highlighted part to
service apache2 reload
.
-
How to list and view all current cron jobs?
Cron is a command-line job scheduler on Unix-like systems. It allows you to run automated tasks in the background and it's especially useful for repetitive jobs.
Questions -
How to prevent duplicate cron jobs from running?
Sometimes you may find that duplicate cronjobs are running at the same time. This may happen when the cronjob takes longer to complete than its execution interval. Here is a simple way to prevent this from happening ever again.
Questions -
How to set up a cron job for a specific time and date?
In this quick tutorial, we will take a look at how to set up a cron job to run at a specific time.
Questions -
How to start logging cron job output to syslog on Ubuntu 20.04?
In this quick tutorial, we will take a look at how to redirect output from cron jobs to the main system log.
Questions
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for us
Build on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
[email protected]or submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github