Skip to Content

How to install free SSL with Let’s Encrypt?

Setting up free SSL on your website with Let’s Encrypt


Overview: This article explains how to obtain and install a free SSL certificate from Let’s Encrypt to secure your website.


You can automatically enable HTTPS on your website with EFF’s Certbot, deploying Let’s Encrypt certificates

Step 1. Install snapd

    Installing snap on Red Hat Enterprise Linux (RHEL) / Centos

     Adding EPEL Repo RHEL

      The EPEL repository can be added to a RHEL 8 system with the following command:

root@gateway:~# sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

root@gateway:~# sudo dnf upgrade

  The EPEL repository can be added to a RHEL 7 system with the following command:

root@gateway:~# sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Adding the optional and extras repositories is also recommended:

root@gateway:~# sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"

root@gateway:~# sudo yum update

Adding EPEL to CentOS

The EPEL repository can be added to a CentOS 8   system with the following command:

root@gateway:~# sudo dnf install epel-release

root@gateway:~# sudo dnf upgrade

 The EPEL repository can be added to a CentOS 7 system with the following command:

root@gateway:~# sudo yum install epel-release

Installing snapd

root@gateway:~# sudo yum install snapd

Once installed, the systemd unit that manages the main snap communication socket needs to be enabled: 

root@gateway:~# sudo systemctl enable --now snapd.socket

To enable classic snap support, enter the following to create a symbolic link between /var/lib/snapd/snap and /snap:

root@gateway:~# sudo ln -s /var/lib/snapd/snap /snap

Installing snap on Debian 

On Debian 10 (Buster) and Debian 9 (Stretch), snap can be installed directly from the command line:

root@gateway:~# sudo apt update

root@gateway:~# sudo apt install snapd 

 Installing snap on Ubuntu

  If you’re running Ubuntu 16.04 LTS (Xenial Xerus) or later, you don’t need to do anything. Snap is already installed and ready to go.

 

Step 2. Ensure that your version of snapd is up to date

  Execute the following instructions on the command line on the machine to ensure that you have the latest version of snapd.

root@gateway:~# sudo snap install core; sudo snap refresh core

Note: For Centos7 Use the following command to ensure that you have the latest version of snapd.

root@gateway:~# sudo snap install core ; sudo snap refresh core

Step 3. Remove certbot-auto and any Certbot OS packages 

       If you have any Certbot packages installed using an OS package manager like apt, dnf, or yum, you should remove them before installing the Certbot snap to ensure that when you run the command certbot the snap is used rather than the installation from your OS package manager. The exact command to do this depends on your OS, but common examples are sudo apt-get remove certbot, sudo dnf remove certbot, or sudo yum remove certbot.

Step 4. Install Certbot

 Run this command on the command line on the machine to install Certbot.

root@gateway:~# sudo snap install --classic certbot

Note:  

"error: system does not fully support snapd: cannot mount squashfs image using "squashfs": mount: /tmp/sanity-mountpoint-024761912: mount failed: Operation not permitted."

If you get this error while installing cerbot with snap, Please run the following commands to install certbot and continue from step 6.

Usually  you will get the above error while trying to install certbot with snap package manager in containerized environment such as LXC,OpenVZ, etc.

sudo apt install certbot

sudo apt-get install python3-certbot-apache or sudo apt-get install python-certbot-apache

Note: 

"error: system does not fully support snapd: cannot mount squashfs image using "squashfs": mount: /tmp/sanity-mountpoint-024761912: mount failed: Operation not permitted."

If you get this error while installing cerbot with snap, Please run the following commands to install certbot and continue from step 6.

Usually  you will get the above error while trying to install certbot with snap package manager in containerized environment such as LXC,OpenVZ, etc.

root@gateway:~# sudo apt install certbot

root@gateway:~# sudo apt-get install python3-certbot-apache or sudo apt-get install python-certbot-apache

 Step 5. Execute the following instruction on the command line on the machine to ensure that the certbot command can be run.

root@gateway:~# sudo ln -s /snap/bin/certbot /usr/bin/certbot

Step 6. Run this command to get a certificate and have Certbot edit your Apache configuration automatically to serve it, turning on HTTPS access in a single step.

Note: Make sure to add virtualhost configuration for the domain.

Let's encrypt will not work with the default configuration. You should create a virtual host configuration and the configuration name should be the domain name.
For example: If your server name/domain name is example.com it should be example.com.conf

root@gateway:~# sudo certbot --apache

Renew Let's Encrypt Certificates & Test automatic renewal

       The Certbot packages on your system come with a cron job or systemd timer that will renew your certificates automatically before they expire. You will not need to run Certbot again, unless you change your configuration. You can test automatic renewal for your certificates by running this command:

root@gateway:~# sudo certbot renew

The command to renew certbot is installed in one of the following locations :

/etc/crontab/

/etc/cron.*/*

systemctl list-timers

More detailed information  can be found in  Certbot documentation

Related Articles: