Chanaka Rathnayaka

Chanaka Rathnayaka

Security Leader. Cloud Architect. Builder.

Manually generating free SSL certificates with Let’s Encrypt (certbot)

Manually generating free SSL certificates with Let’s Encrypt (certbot)

This article explains how to create SSL certificates using Let’s Encrypt’s manual plugin. You may need to generate these free SSL certificates in situations like the ones below, particularly when the automated method is not an option.

  • No direct access to the Web Server.
  • Unsupported/custom web server setups.
  • Creating wildcard certificates which require DNS challenge

You can use the following command to generate free SSL certificates with Let’s Encrypt via certbot using the manual plugin. Certbot uses Let’s Encrypt to generate certificates by default.

1. Installing Certbot

Certbot is the official Let’s Encrypt client:

Terminal
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot

Further installation instructions can be found in their official guide.

2. Generating a Certificate

This command will prompt you to provide an email address for notifications. It will then generate a TXT record that needs to be added to your DNS provider for certbot to verify domain ownership.

Terminal
certbot certonly --manual --preferred-challenges=dns --key-size 4096 -d mydomain.com -d www.mydomain.com
# COMMAND BREAKDOWN
# --manual: Indicates you want to handle the DNS challenge manually.
# --preferred-challenges=dns: Tells Certbot to use the DNS challenge method.
# --key-size 4096: Specifies that you want to use a 4096-bit RSA key for better security.
# -d mydomain.com -d www.mydomain.com: This includes both the root domain mydomain.com and subdomain www.mydomain.com to ensure that both are covered by the certificate.
# you can give a wildcard domain to this if needed.

3. Verifying the domain ownership

Certbot will output specific DNS records (TXT records) that you need to add to your DNS provider to complete the DNS verification process. Following is a sample output,

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:
_acme-challenge.mydomain.com.
with the following value:
5lBTUVMngGj346hseQgIqAE29JusY76g2moq2gnETVBuw
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Once you’ve added the required DNS records, Certbot will verify domain ownership and issue the certificate. It may take a few minutes for the DNS to update the TXT records. If everything is successful, certbot will display the locations where the certificates are saved locally.

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mydomain.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/mydomain.com/privkey.pem
This certificate expires on 2024-12-19.
These files will be updated when the certificate renews.

Please note that these certificates are valid for only 90 days, and since they were created using the manual plugin, auto-renewal is not enabled. You will need to renew them manually.

Cheers !!

Enjoyed this post? Work with me or subscribe to my newsletter.