How to Install Let’s Encrypt Free SSL (Certbot) on Ubuntu with Automatically Renew
Let’s Encrypt offers complimentary SSL certificates for securing your websites with encrypted connections. Certbot, an open-source tool, enables the straightforward generation of Let’s Encrypt SSL certificates on your self-managed Linux server at no cost.
Now you need to log in to your server using SSH (Currently I am using AWS EC2 Medium Server)
Install Certbot in Ubuntu with snapd
Step 1: Install snapd
sudo apt install snapd
Step 2: Ensure you have the latest snapd version installed
sudo snap install core; sudo snap refresh core
Step 3: Install Certbot with snapd
sudo snap install --classic certbot
Step 4: Create a symlink to ensure Certbot runs
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Create an SSL Certificate with Certbot
Step 1: Create SSL certs for all Domains and configure redirects in the Web Server
Create SSL certs for all domains and configure redirects in the Nginx Web Server
sudo certbot --nginx
Create SSL certs for all domains and configure redirects in the Apache Web Server
sudo certbot --apache
Create SSL certs for a specified domain that you hosted on Nginx Web Server
sudo certbot --nginx -d example.com -d www.example.com
Create SSL certs for a specified domain that you hosted on Apache Web Server
sudo certbot --apache -d example.com -d www.example.com
Create the SSL certificates without modifying system files (Only install SSL certs)
sudo certbot certonly --apache
sudo certbot certonly --nginx
Step 2: Enter an email address for renewal and security notices.
Step 3: Agree to the terms of service.
Step 4: Specify whether to receive emails from EFF.
Step 5: If prompted, choose whether to redirect HTTP traffic to HTTPS – 1 (no redirect, no further changes to the server) or 2 (redirect all HTTP requests to HTTPS).
Automatically Renew Let’s Encrypt Certificates
Certbot certificates expire after 90 days, so it’s essential to set up automatic renewal. Certbot usually creates a cron job for you, but you can verify it’s set up by running:
Step 1: Open the crontab file.
sudo crontab -e
Step 2: Add the certbot command to run daily
0 12 * * * /usr/bin/certbot renew --quiet
Step 3: Save and close the file. All installed certificates will be automatically renewed and reloaded.
sudo crontab -l