avatar

ShīnChvën ✨

Effective Accelerationism

Powered by Druid

How to Install Certbot with Nginx on Linux

Mon Nov 09 2020

Certbot is a handy command-line tool for Let's Encrypt, enabling you to set up and update SSL certificates effortlessly via straightforward commands.

Though the official guide suggests using snapd for installation, I find using the built-in package manager of each Linux distribution to be simpler.

So, let's get started…

Installation on Ubuntu 20.04 / 22.04

Refer to this guide: Securing Nginx with Let's Encrypt on Ubuntu 20.04

Run this command:

sudo apt install certbot python3-certbot-nginx

Installation on CentOS 7

Refer to this guide: Securing Apache with Let's Encrypt on CentOS 7

Execute these commands:

sudo yum install epel-release
sudo yum install certbot python2-certbot-apache mod_ssl

Setting Up Certificates

Use the command below to set up certificates for your domain.

sudo certbot --nginx

This command will display the list of domains on your server. Choose the one you want to secure with an SSL certificate, and the tool will handle the rest.

Updating Certificates

Use the command below to update certificates for your domain.

## Test
sudo certbot renew --dry-run
## Update
sudo certbot renew

Auto-updating Certificates

After setting up certificates, if you see a message like this:

Certbot has set up a scheduled task to automatically renew this certificate in the background.

It means that Certbot has set up a cron job to update your certificates automatically.

[Optional] If you didn't see this message, you can set up a cron job manually to update your certificates automatically.

Run the command below to edit crontab.

sudo crontab -e

Add the following line to the end of the file.

0 0 1 * * certbot -q renew

The -q option is used to suppress output when running the certbot renew command. This means that the command will not produce any output, making it useful for automated scripts or cron jobs.