Chapter 3 · Lesson 11 of 22
Domains and HTTPS

Renew Let's Encrypt certificates and test renewal

Let's Encrypt certificates are valid for 90 days, and certbot renews them automatically through a timer that you can test with a dry run.

By the end you will

Confirm that your Let's Encrypt certificate renews on its own, using a dry run and the timer.

Time
14 min
Level
Intermediate
Check
4 questions
You need
  • A certificate issued by certbot on your server

A certificate that expires on a Saturday night takes your site down with a browser warning that most visitors will not click through. Certificates last 90 days, so renewal has to work unattended. This lesson shows how to confirm that it will, before it matters.

How it works#

Certbot does not renew on a fixed calendar date. A timer wakes up regularly, and each time certbot looks at every certificate it manages. It only renews those that are close to expiry, and leaves the rest alone. So running it often is safe and cheap.

Each certificate has a renewal config under /etc/letsencrypt/renewal/. It records how the certificate was first obtained (the nginx plugin, the webroot method or standalone) and renewal reuses the same method. That is why a certificate issued with the nginx plugin still needs nginx running and port 80 reachable at renewal time.

The timer is a systemd unit. A snap install uses snap.certbot.renew.timer. The Ubuntu apt package uses certbot.timer. Either way, if the timer exists and the dry run passes, you are covered.

Step 1: List your certificates#

bash
sudo certbot certificates

Each certificate shows its domains, expiry date and file paths.

What you should see: a block per certificate with Certificate Name, Domains, Expiry Date (including how many days are left, or a VALID note) and Certificate Path.

Step 2: Test renewal with a dry run#

bash
sudo certbot renew --dry-run

This simulates renewal against Let’s Encrypt’s staging service. Nothing live is replaced. It runs the whole path: validation, reload hooks and all.

What you should see: a line per certificate saying the simulated renewal succeeded, and a final message that all simulated renewals succeeded.

Step 3: Find the renewal timer#

bash
systemctl list-timers

Look for a certbot line (the snap install shows snap.certbot.renew.timer, the apt install shows certbot.timer). It lists when it last ran and when it runs next.

What you should see: a row with a NEXT time in the future and a LAST time that is not n/a once it has run at least once.

Step 4: Make sure the server reloads#

If you used certbot --nginx, the plugin reloads nginx after renewal. For a custom setup (webroot or standalone), add a deploy hook so the new files are used:

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

Certbot runs a deploy hook only when a certificate was actually renewed. To keep it permanent, put an executable script in /etc/letsencrypt/renewal-hooks/deploy/.

Check it worked#

The dry run ends with a message that all simulated renewals succeeded, and the timer has a next run time. Also check the live certificate from outside:

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

That prints notAfter= with the date visitors see. After a real renewal it should move forward by about three months.

Edge cases and gotchas#

  • Port 80 must be open even for an HTTPS-only site. HTTP-01 validation comes in over port 80. If a firewall rule closed it after launch, renewal quietly fails until the certificate nears expiry.
  • A redirect to HTTPS is fine, a redirect to another host is not. Let’s Encrypt follows redirects, but the challenge must end up answered by your server. Blocking /.well-known/acme-challenge/ behind a login or app route breaks it.
  • Standalone mode needs port 80 free. If nginx is running, a certificate issued with --standalone fails to renew. Switch the certificate to the nginx or webroot method.
  • The domain moved or was removed. Certbot keeps trying old certificates. Delete the ones you no longer use with sudo certbot delete --cert-name example.com.
  • Staging certificates look broken. A certificate from the staging service is not trusted by browsers. A dry run does not install one, but a test issue with --staging does.
  • Rate limits exist. Repeated failed or duplicate real requests can get you temporarily blocked. Use --dry-run for experiments, not repeated live runs.
  • The clock matters. If the server time drifts a lot, validation and expiry checks can misbehave. Keep time sync on (timedatectl).

Troubleshooting#

SymptomLikely causeFix
Challenge failed for domain example.comDNS or port 80 problemPoint the A record here, open port 80, retry the dry run
Timeout during connect (likely firewall problem)Firewall or cloud group drops port 80Allow inbound TCP 80
Could not bind TCP port 80Another program uses port 80 in standalone modeUse the nginx or webroot method instead
No certbot timer in the listPackage not installed or timer disabledInstall certbot, then systemctl list-timers --all
Failed to renew certificate ... with error for a retired domainOld certificate still managedRemove it with certbot delete --cert-name
The following certificates are not due for renewal yetNot within the renewal windowNothing to fix. Use --dry-run to test, or --force-renewal only if you truly must
too many certificates or rate limit messageRepeated real issuanceWait, and use --dry-run or --staging for tests
Renewal worked but the site shows the old certificateWeb server never reloadedAdd a deploy hook that reloads it

Real-world scenario#

Eleven weeks after launch you get an email from Let’s Encrypt saying a certificate is about to expire. That should not happen if renewal works, so you investigate.

sudo certbot certificates shows the expiry is close. sudo certbot renew --dry-run fails with a challenge error and a timeout. You check the firewall with sudo ufw status and see port 80 is no longer allowed: someone tightened the rules to “HTTPS only” last month. You allow it again with sudo ufw allow 80/tcp (see the ufw lesson), rerun the dry run and it passes.

You then run sudo certbot renew. It renews, and because the site was set up with the nginx plugin, nginx reloads itself. To confirm from outside, you run the openssl s_client check from the checking section and the notAfter date has moved forward. Finally you read systemctl list-timers to confirm the timer exists, and add an uptime check so a real expiry would alert you earlier next time (see monitor uptime simply).

Quick reference#

bash
sudo certbot certificates            # what exists and when it expires
sudo certbot renew --dry-run         # safe test against staging
sudo certbot renew                   # renew anything near expiry
systemctl list-timers | grep -i certbot   # is the timer there
sudo certbot delete --cert-name example.com   # retire a certificate
ls /etc/letsencrypt/renewal-hooks/deploy/     # deploy hooks

Security and safety notes#

  • Do not delete files under /etc/letsencrypt/live by hand. They are links to the archive, and deleting them breaks renewal. Use certbot delete.
  • Test with --dry-run first. Real repeated issuance can hit rate limits.

Next#

Prefer something that handles all of this itself? See Automatic HTTPS with Caddy.

Check what you learned4 questions
1What does certbot renew --dry-run do to your live certificate?
2Where do you check that automatic renewal is scheduled?
3Renewal fails after you moved the domain to a new server. What is the likely reason?
4Certbot renewed the files on disk, but visitors still get the old certificate. What is missing?

Frequently asked questions

Do I have to renew certificates by hand?

No. Certbot installs a timer that tries renewal regularly and only renews certificates that are close to expiry. You only need to check that the timer runs.

Does a dry run change my real certificate?

No. It uses the staging environment to prove renewal would work and leaves your live certificate alone.

I renewed, but the browser still shows the old expiry date. Why?

The web server keeps the old certificate in memory until it reloads. Reload nginx or restart the service, or add a deploy hook so certbot does it after each renewal.

Do I need to open port 80 if my site is only HTTPS?

Yes, if you use the HTTP-01 challenge. Let's Encrypt validates over port 80 from the internet, so closing it makes renewal fail even though visitors only use 443.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios