Tutorials, Ubuntu, Development

If you want a quick solution for adding SSL/TLS to your website, then you should definitely go ahead with the Internet Security Research Group’s (ISRG) Let’s Encrypt project.

There are many reasons to have SSL certificate on your website.

Let’s Encrypt has started supporting wildcard certificates using its new ACME2 protocol. So we can have one SSL certificate i.e *.example.com which can be used in all subdomains i.e test.example.com , test1.example.com etc.

Certbot is not available in the default ubuntu repository. Run the below command to add ppa repository.

sudo add-apt-repository ppa:certbot/certbot

This will add the repository from where certbot can be installed.

Update packages using below command.

sudo apt update

Run below command to install certbot

sudo apt install certbot

Make sure that you are using Certbot version 0.22 or above. Certbot before the version 0.22 does not support wildcard certificate.

 

Steps to generate wildcard certificate

$ sudo certbot certonly --manual -d *.example.com -d example.com --agree-tos --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory

Replace example.com with your own domain name.
We need to create certificate for both *.example.com and example.com. Because by default wildcard certificate will not be generated for domain name without www.

Once you run above command, you will get to see the following kind of output.

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Plugins selected: Authenticator manual, Installer None

Obtaining a new certificate

Performing the following challenges:

dns-01 challenge for example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:
sdsdfj2812121m2n1nsmnsmnxzmxnzmxnzmxnzmxnzmxnzmxzx
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Press Enter to Continue

In this step, you need to create a DNS TXT record under name _acme-challenge . In needs to be configured inside your Domain provider like GoDaddy etc.

You need to wait for some time as new DNS record takes time to be propagated over the internet. I waited for 10 minutes and pressed enter.

Then you will get the following output.

Press Enter to Continue

Waiting for verification...

Cleaning up challenges

IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem

Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem

Your cert will expire on 2019-02-27. To obtain a new or tweaked

version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"

- 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

Congratulations!! Your wildcard certificate is generated. You can use this wildcard certificate with any sub-domain you create for your domain name.

Then you need to manually configure apache virtual host / ngnix location with correct SSL cert path.

<VirtualHost *:443>

ServerName example.com

ServerAlias www.example.com

ServerAdmin info@example.com

DocumentRoot /var/www/www.example.com/public_html

<Directory /var/www/www.example.com/public_html>

Options -Indexes +FollowSymLinks

AllowOverride All

Order allow,deny

allow from all

</Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com-error.log

CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem

SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>
</IfModule>

Now verify the syntax of your configuration edits:

sudo apache2ctl configtest

Once your configuration file’s syntax is correct, reload Apache to load the new configuration:

sudo systemctl reload apache2

Certbot can now find the correct VirtualHost block and update it.

Now you are all set !!

 

This article was originally posted on Medium