Issuing and renewing Let's Encrypt certificates automatically with certbot and ACME on Ubuntu 24.04

  1. Goal
  2. What ACME and Let's Encrypt are
  3. Preparation
  4. Steps
  5. 1. Try the staging environment first
  6. 2. Issue the real certificate
  7. 3. Understand automatic renewal
  8. 4. Reload nginx after renewal
  9. Checking
  10. Common errors
  11. Summary
  12. References

Goal

After this article you will be able to issue a free TLS certificate from Let's Encrypt for a domain, understand how automatic renewal works, and check whether renewal is able to run.

The background knowledge is the TLS handshake and the certificate chain (the first article of this series).

Once you have a certificate, you can put nginx in front of your application as the TLS termination point, as described in nginx as a reverse proxy for an app: proxy_pass, X-Forwarded-* headers and timeouts.

If you run into errors, continue with Common certificate errors and how to check them with openssl: expiry, missing intermediates, wrong hostname.

What ACME and Let's Encrypt are

ACME (Automatic Certificate Management Environment) is a protocol standardised in RFC 8555.

The idea: your machine contacts the CA by itself, the CA issues a "challenge", and if the machine proves it controls the domain, the CA signs a certificate.

The whole process needs no one to click a button.

Let's Encrypt is a non-profit CA that issues free certificates through ACME.

Its certificates have a short lifetime (currently 90 days) to force renewal to be automated; it has also announced plans to shorten lifetimes further, so check the official site for the current figure.

Two common kinds of challenge:

This article uses HTTP-01.

Preparation

The certbot instructions page recommends installing with snap on Ubuntu:

sudo snap install --classic certbot
sudo ln -s /snap/certbot/current/bin/certbot /usr/bin/certbot
certbot --version

If you prefer apt, Ubuntu also has a certbot package in its own repository, but the version may be older; read the official instructions page to choose the approach that suits you.

Steps

Steps

1. Try the staging environment first

Let's Encrypt has issuance limits, so do not experiment repeatedly against the real environment.

Use --dry-run to run the whole flow without saving a real certificate, or --test-cert to obtain a test certificate (browsers will not trust it):

sudo certbot certonly --nginx -d example.com -d www.example.com --dry-run

2. Issue the real certificate

The simplest way is to let certbot edit the nginx configuration for you:

sudo certbot --nginx -d example.com -d www.example.com

Certbot asks for an email address for notifications (only to receive expiry warnings), accepts the terms, and then configures HTTPS.

If you prefer to edit the configuration files yourself, use the obtain-only mode:

sudo certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com

On success, the files are in /etc/letsencrypt/live/example.com/:

File

fullchain.pem

Contents

the server certificate plus the intermediate certificates (use this for nginx)

File

privkey.pem

Contents

the private key (keep it secret, never share it)

File

cert.pem

Contents

the server certificate only

File

chain.pem

Contents

the intermediate certificates only

In nginx the two lines you need are ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; and ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;.

Use fullchain.pem, not cert.pem, otherwise the server will be missing the intermediate certificate.

3. Understand automatic renewal

The snap installation ships with a systemd timer. Look at it with:

systemctl list-timers | grep certbot

Certbot only really renews certificates with fewer than 30 days of validity left, so running it often does no harm. To see the state of your certificates:

sudo certbot certificates

4. Reload nginx after renewal

The new certificate is on disk, but nginx keeps the old one in memory until it is reloaded. The --nginx mode usually takes care of this, but with certonly mode you should add a deploy hook:

sudo certbot renew --deploy-hook "systemctl reload nginx"

Or place an executable script in /etc/letsencrypt/renewal-hooks/deploy/; certbot runs the scripts there after every successful renewal.

Checking

  1. Run the whole renewal flow without changing anything real:

sudo certbot renew --dry-run

The expected result is a message saying that all simulated renewals succeeded.

  1. See the certificate the server is presenting:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -issuer

The notAfter date must be far away and issuer is an intermediate CA of Let's Encrypt.

Common errors

Safety note: never put privkey.pem in a code repository, a screenshot or a chat channel. If you suspect the key has leaked, issue the certificate again with a new key and do not use --reuse-key.

Summary

ACME turns requesting a certificate into something the machine does by itself, Let's Encrypt provides free certificates, and certbot connects the two to nginx.

The habits worth keeping are issuing with certbot, testing with --dry-run, making sure the renewal timer is running and reloading nginx after each certificate change.

The article is based on official documentation as of November 2026; compare it with the certbot and Let's Encrypt pages because details such as certificate lifetime may change.

References

Issuing and renewing Let's Encrypt certificates automatically with certbot and ACME on Ubuntu 24.04