Install a Let’s Encrypt SSL certificate on Ubuntu with Certbot
Let’s Encrypt provides free TLS certificates. This guide shows how to install Certbot, obtain a certificate and test renewal on Ubuntu.
Let’s Encrypt issues free certificates for secure website connections. Certbot helps obtain and manage them on a Linux server. The original tutorial targets Ubuntu 20.04 and uses a Python virtual environment. Connect to the server over SSH with an account that can run sudo.
Install Certbot on Ubuntu 20.04
Install the Python packages needed by this original virtual-environment procedure. Check current Certbot instructions before using the commands on another Ubuntu release.
sudo apt install python3 python3-venv libaugeas0
Create a virtual environment and update its copy of pip.
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
Install Certbot with the Apache plugin, or choose the Nginx plugin instead.
sudo /opt/certbot/bin/pip install certbot certbot-apache
Alternatively, for Nginx:
sudo /opt/certbot/bin/pip install certbot certbot-nginx
Create a symbolic link to the Certbot executable.
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
Create a certificate with Certbot
Run Certbot to request a certificate and configure your web server. The certonly mode requests a certificate without automatically editing the server configuration.
For Apache, request certificates and configure the web server:
sudo certbot --apache
For Nginx, use:
sudo certbot --nginx
For a specific hostname and its www variant, use:
sudo certbot --apache -d example.com -d www.example.com
Provide an email address for renewal notices and security alerts.
Accept the service terms and choose whether to receive email from the EFF.
If prompted, choose whether to redirect HTTP traffic to HTTPS.
Certificate maintenance and troubleshooting
After installation, check for mixed content in your website. Certificate files for each domain are stored under:
cd /etc/letsencrypt/live
Inspect the renewal timer or cron configuration used by your installation. The renewal schedule depends on how Certbot was installed.
systemctl show certbot.timer
cat /etc/cron.d/certbot
Test the renewal process without issuing a production certificate.
sudo certbot renew --dry-run
Additional HTTPS protection
A certificate and an HTTP-to-HTTPS redirect are important, but they do not cover every transport-security issue.
HTTP Strict Transport Security (HSTS) tells compatible browsers to prefer HTTPS for your site. Configure it carefully in Apache or Nginx only after HTTPS works reliably for the relevant hostnames.
Share
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0