How To Secure Apache with Let’s Encrypt on Ubuntu 20.04

In this article, we want to teach you How To Secure Apache with Let’s Encrypt on Ubuntu 20.04.

Let’s Encrypt is a Certificate Authority (CA) that facilitates getting and installing free TLS/SSL certificates, by enabling encrypted HTTPS on web servers.

Requirements

You need to log in as a non-root user with sudo permissions and a firewall. to do that follow the article about the Initial server setup with Ubuntu 20.04.

You need your domain name.

Also, you should install Apache and set up its Virtual host on Ubuntu 20.04 by visiting these articles about How to install Apache on Ubuntu 20.04 and How to set up Apache virtual host on Ubuntu 20.04.

After these, Let’s go back to Secure Apache with Let’s Encrypt on Ubuntu 20.04.

How To Secure Apache with Let’s Encrypt on Ubuntu 20.04

Install certbot on Ubuntu 20.04

First of all, you need to install “certbot” to get an SSL certificate with Let’s Encrypt.

sudo apt install certbot python3-certbot-apache

Answer “y” to complete the installation.

Now certbot is now installed on your Ubuntu 20.04.

Let’s get an SSL certificate for your domain name.

How to get an SSL certificate from Let’s Encrypt

You can get your SSL certificate with Let’s Encrypt by following these steps:

sudo certbot --apache

It will ask you some questions. the first will ask you to enter your email address for renewal notifications and security notices:

Output
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

After entering your email address, press enter to the next step, you will be asked to confirm if you agree to Let’s Encrypt terms of service. press ‘A’ to accept and press enter to continue:

Output
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)agree/(C)cancel : A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

At this point, you will be asked to share your email address with the Electronic Frontier Foundation:

Otput
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)yes/(N)no: N

Press ‘N’ to continue, if you want to receive the information type ‘Y’.

In this step, It is important to set up correctly your virtual hostname at the beginning of the article. select the domains you want to activate HTTPS for.

Output
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: stacku.orcacore.net
2: www.stacku.orcacore.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

you will see your output like this:

Output
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for stacku.orcacore.net
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/stacku.orcacore.net-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/stacku.orcacore.net-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/stacku.orcacore.net-le-ssl.conf

In the next step, you will be asked to choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.

Output
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

At this point, the certbot configuration is finished. and you will see this in your output:

Output
Congratulations! You have successfully enabled https://stacku.orcacore.net
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=stacku.orcacore.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/stacku.orcacore.net/fullchain.pem
  Your key file has been saved at:
   /etc/letsencrypt/live/stacku.orcacore.net/privkey.pem
   Your cert will expire on 2021-11-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Your certificate with Let’s Encrypt on Ubuntu 20.04 is now installed and loaded into Apache’s configuration.

Type your domain name in your web browser.

https://stacku.orcacore.net

you will see a page like the image below:

SSL testpage Lets Encrypt on Ubuntu 20.04

 

As you can see the lock icon is in the address bar.

Here you can use the SSL Labs server test to verify your certificate from Let’s Encrypt too. you go to the page and enter your hostname there.

How To set up Auto-Renewal Of the Lets Encrypt Certifications

In this article, we learn How to Secure Apache with Let’s Encrypt on Ubuntu 20.04 and configure it. Now, you should know, that Let’s Encrypt certificates are valid for 90 days, but it’s better to renew them every 60 days automatically.

sudo certbot renew --dry-run

You will see this in your output:

Output
Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/stacku.orcacore.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry

**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

Conclusion of How to Secure Apache with Let’s Encrypt on Ubuntu 20.04

Here you learn about the installing certbot and get the SSL certification from Let’s Encrypt. and renew the certifications.

Hope you enjoy this article about How to Secure Apache with Let’s Encrypt on Ubuntu 20.04.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular