How to Install Let's Encrypt SSL Certificate on an Ubuntu 20.04 Cloud Server?

29-01-2024 03:28:53

Let's Encrypt is an automated, free TLS/SSL certificate authority provided by the Internet Security Research Group (ISRG). This article explains how to install a Let's Encrypt SSL certificate on an Ubuntu 20.04 cloud server, applicable for both Apache and Nginx web servers. Once installed, the web server will possess a valid SSL certificate and will be able to redirect HTTP requests to HTTPS.

Installing Certbot

Ensure snapd is up to date:

$ sudo snap install core; sudo snap refresh core

Remove any residual Certbot:

$ sudo apt-get remove certbot

Install Certbot using snap:

$ sudo snap install --classic certbot

Create a symlink for Certbot:

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

Installing the SSL Certificate

Run Certbot to install the SSL certificate. The options and their meanings for the Certbot command are as follows:

  • --apache: Use Apache server
  • --nginx: Use Nginx server
  • --redirect: Redirect HTTP requests to HTTPS
  • -d example.com -d www.example.com: Install a multi-domain certificate (SAN), supporting up to 100 domains
  • -m admin@example.com: Set the notification email for the certificate
  • --agree-tos: Agree to the terms of service

Additional help can be obtained using the certbot --help command.

1.Installing SSL Certificate on Apache:

# certbot --apache --redirect -d example.com -d www.example.com -m admin@example.com --agree-tos

2.Installing SSL Certificate on Nginx:

# nano /etc/nginx/conf.d/default.conf

Change the server_name to the actual domain name:

server {
    server_name  example.com www.example.com;

Execute the installation command:

# certbot --nginx --redirect -d example.com -d www.example.com -m admin@example.com --agree-tos

Setting Up Automatic Renewal

The validity of Let's Encrypt certificates is 90 days. Certbot will update the system's crontab to implement automatic certificate renewal.

Verify the timer status:

# systemctl list-timers | grep 'certbot\|ACTIVATES'

Confirm the status of the scheduled task:

# ls -l /etc/cron.d/certbot

Ensure the renewal is functioning properly:

# certbot renew --dry-run

The above are the methods to install a Let's Encrypt certificate using Certbot. For more information, refer to the official Certbot documentation.

https://certbot.eff.org/instructions