How to have a Free SSL Certificate with Let’s Encrypt on Ubuntu Server

Share this post on:

In today’s digital landscape, HTTPS is not just an optional feature but a critical security standard for all websites. It plays a vital role in protecting user data, fostering trust, and even influencing search engine rankings.

HTTPS ensures that data transmitted between a user and a website is encrypted, safeguarding sensitive information such as passwords, credit card details, and personal data from being intercepted or read by unauthorized parties. This encryption is especially crucial when users are browsing on public or unsecured networks, as it effectively prevents data breaches and upholds user privacy and security.

To make the transition to HTTPS easier, Let’s Encrypt, a trusted Certificate Authority (CA), provides free TLS/SSL certificates. Their service simplifies the process of enabling HTTPS on web servers by offering Certbot, an easy-to-use software client that automates most of the steps required to obtain and install these certificates.

With Let’s Encrypt, website administrators can enhance security, protect their users, and build trust, all without incurring additional costs. Switching to HTTPS has never been easier, making it an essential step for anyone managing a website today.

n this guide, we’ll walk you through using Certbot to obtain a free SSL certificate for your Apache server on Ubuntu 20.04. We’ll also ensure that the certificate is configured to renew automatically, so you don’t have to worry about manual updates.

To keep things organized, this tutorial uses a dedicated virtual host file for setting up your website instead of modifying Apache’s default configuration file. This approach ensures a cleaner and more maintainable server configuration.

To get started, you’ll need two essential packages:

  • certbot – The Certbot client that interacts with Let’s Encrypt to obtain the SSL certificate.
  • python3-certbot-apache – A plugin that integrates Certbot with Apache, allowing you to automate both the certificate issuance and HTTPS configuration on your web server in just one command.
    This streamlined process makes it simple to secure your website with HTTPS quickly and effectively.

Install Certbot Package

Install the certbot package using the apt-get command in ubuntu terminal

sudo apt-get install certbot python3-certbot-apache

Press Yes if it asks for confirmation and the terminal will take some time to fetch the certbot package from the repository and install it on your system

Configure Apache Virtual Hosts

Certbot has now been successfully installed on your server. The next step is to verify your Apache configuration to ensure that your virtual host is correctly set up. This is crucial for Certbot to detect your domains and automatically reconfigure your web server to use the newly generated SSL certificate.

To automatically obtain and configure SSL, Certbot relies on the correct virtual host in your Apache configuration. It identifies your domain name(s) from the ServerName and ServerAlias directives within your VirtualHost block. If you’ve already set up a virtual host (In my case it is at /etc/apache2/sites-available/000-default.conf) during the Apache installation, ensure these directives are properly configured for your domain.

sudo nano /etc/apache2/sites-available/000-default.conf

Open the file with any editor of your choice and make changes to the following variables.

Update it accordingly. When you’re done, save the file and quit the editor. and then, run the following command to validate that our variables are correctly set and saved:

sudo apache2ctl configtest

If everything is correct the command should return “Syntax OK” . If there is an error, just check the all the syntext are correct and make the file perfect again.

Then Reload the Apache service

sudo systemctl reload apache2

Obtain the SSL with Certbot

Once Certbot is installed, and Virtualhosts are set, use the Apache plugin to obtain an SSL certificate for your domain and configure your server automatically. Run:

sudo certbot --apache

The script will guide you through a series of prompts to configure your SSL certificate. The first step is to provide a valid email address, which will be used for renewal notifications and important security updates:

After entering a valid email address, press ENTER to proceed. Next, you’ll be prompted to agree to Let’s Encrypt’s terms of service.

To confirm, press A and then ENTER.
You will then be asked if you’d like to share your email with the Electronic Frontier Foundation to receive updates and information. To decline, type N; to subscribe, type Y. Press ENTER to continue.

In the next step, Certbot will ask which domains you want to enable HTTPS for. These domains are automatically retrieved from your Apache virtual host configuration, so it’s essential to ensure your ServerName and ServerAlias settings are correctly configured.

To enable HTTPS for all listed domains (recommended), simply leave the prompt blank and press ENTER. If you prefer to activate HTTPS for specific domains, enter their corresponding numbers (separated by commas or spaces) and then press ENTER to proceed.

You’ll see output like this:

Next, you’ll be prompted to select whether or not you want HTTP traffic redirected to HTTPS. In practice, this means that if someone visits your website via the unencrypted HTTP protocol, they will automatically be redirected to the secure HTTPS version of your site.

Select option 2 to enable this redirection, or choose option 1 if you prefer to keep HTTP and HTTPS as separate ways to access your website.

Once this step is complete, Certbot will finalize the configuration. You’ll then see the final remarks about your new certificate, including details on where to find the generated files. Additionally, you’ll be provided with instructions on how to test your configuration using an external tool to verify the authenticity of your certificate.

Congratulations!
Your certificate is now successfully installed and integrated into Apache’s configuration. To verify, try reloading your website at your Domain, since I have installed and enabled it on my website it Is perfectly working on https://library.cup.edu.in
Further you can check your browser’s security indicator. It should show that your site is properly secured, usually by displaying a lock icon in the address bar.

In this tutorial, you’ve installed the Let’s Encrypt client Certbot, configured and applied an SSL certificate for your domain, and ensured that Certbot’s automatic renewal service is active via systemctl. If you have any further questions about using Certbot, their official documentation is a great resource to consult.

Share this post on:

Author: Rupinder Singh

I am a tireless intelligence seeker, coincidentally I am a computer guy too, who is passionate about Information Tools and Open-Source software. I Read Books, play Computer Games, Climb Mountains, when I am not changing the code.

View all posts by Rupinder Singh >

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.