TLS certificate expiry: how to monitor it properly
In short
A TLS certificate expires when automatic renewal fails silently or when the renewed file is never loaded by the web server. Monitor the certificate that is actually served on port 443, from the outside and with the right host name, and alert when fewer than about 14 days remain. Checking the file on disk is not enough.
A TLS certificate expires for one of two reasons: the automatic renewal has been failing without anyone noticing, or the renewal worked but the web server never loaded the new file. Both are caught by the same check: open a TLS connection to the site from the outside, read the expiry date of the certificate that is actually served, and alert when fewer than about 14 days remain. The rest of this article shows how to do that by hand, why certbot fails, and what a reliable check looks like.
How do certificates expire in the first place?
Every certificate carries two dates, notBefore and notAfter. After notAfter, browsers show a full-page warning, API clients refuse the connection, and most visitors leave. There is no grace period.
Certificates from Let's Encrypt and other ACME certificate authorities are typically valid for 90 days or less. They are meant to be renewed automatically, typically when about a third of the lifetime is left. That works well for years, which is exactly the problem: nobody looks at it any more, and the first sign of a broken renewal is the browser warning.
One safety net is gone as well. Let's Encrypt ended its expiry notification e-mails in June 2025. If your plan was "we will get a mail", that plan no longer works.
How do I check the expiry date of a certificate?
Ask the server, not the file system. This command connects to port 443, sends the host name (SNI) and prints the dates of the certificate that comes back:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -datessubject=CN = example.com
issuer=C = US, O = SSL Corporation, CN = Cloudflare TLS Issuing ECC CA 3
notBefore=Sep 26 22:49:11 2026 GMT
notAfter=Dec 25 22:56:35 2026 GMTThree details matter:
-servernameis not optional. A server with several sites picks the certificate by the name the client sends. Without it you may get the default site's certificate and measure the wrong one, which can look perfectly healthy.echo |closes the connection right after the handshake, so the command does not wait for input.- Check every name.
example.comandwww.example.comcan be served by different virtual hosts with different certificates. Add-ext subjectAltNameto see which names a certificate covers.
For scripts, -checkend answers the question "does it expire within N seconds?" through the exit code. 1209600 seconds are 14 days:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -checkend 1209600Certificate will not expireThe exit code is 0 if the certificate is still valid after that time and 1 if it is not. To print the remaining days instead:
end=$(echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -enddate | cut -d= -f2)
echo "$(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 )) days left"38 days leftMail and other services work the same way. Use -starttls smtp on port 587 or 25, and plain -connect on implicit-TLS ports such as 465 or 993.
Why is checking the file on disk not enough?
On the server itself, certbot certificates lists every certificate certbot manages together with its expiry:
sudo certbot certificatesCertificate Name: example.com
Domains: example.com www.example.com
Expiry Date: 2027-02-10 08:14:03+00:00 (VALID: 84 days)
Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pemThat output describes the file. It says nothing about what the running web server presents. Apache and Nginx read certificates at start or reload and keep them in memory. If certbot replaces the file and nobody reloads the service, certbot reports "VALID: 84 days" while browsers already show "expired". A check that reads the file would agree with certbot and stay silent.
The same gap exists when something sits in front of the server: a load balancer, a reverse proxy or a CDN terminates TLS with its own certificate, and the file on the origin server is irrelevant to visitors.
Why does certbot renewal fail?
The common causes, roughly in order of frequency:
- The timer does not run. The Debian and Ubuntu packages install a systemd timer; check it with
systemctl list-timers certbot.timer. With the snap package the unit is calledsnap.certbot.renew.timer. On servers that were migrated or restored from an image, the timer or an old cron entry is sometimes simply missing. - HTTP validation is blocked. The HTTP-01 challenge needs port 80 reachable from the internet and
/.well-known/acme-challenge/served without login, redirect loops or rewrite rules that send the request to an application. - DNS has changed. The domain now points to another server, an
AAAArecord points to an old IPv6 address, or the DNS API token used for DNS-01 validation has expired or was revoked. - The web server was not reloaded. Renewal succeeded, but there is no deploy hook.
- The configuration is broken. A failed
apache2ctl configtestornginx -tmakes plugins and reloads fail.
Test the whole path without touching the real certificate:
sudo certbot renew --dry-runA dry run uses the staging environment of the certificate authority, so it does not count against rate limits and does not replace your files. It should end with a line saying that all simulated renewals succeeded. Errors are logged in /var/log/letsencrypt/letsencrypt.log.
To make sure the web server picks up a renewed certificate, register a deploy hook. It runs only after a successful renewal:
sudo certbot renew --deploy-hook "systemctl reload apache2"Alternatively, place an executable script in /etc/letsencrypt/renewal-hooks/deploy/; certbot runs everything in that directory after each successful renewal. Use reload, not restart, so existing connections are not cut. For Nginx the command is systemctl reload nginx.
What makes a good expiry check?
- It measures from the outside, over a real TLS handshake with SNI, for every host name that matters.
- It warns early enough, but not too early. With renewal at about 30 days before expiry, a healthy certificate never drops below roughly 30 days. A warning at 14 days means the renewal has been failing for two weeks; a critical alert at a few days means it needs attention today. A threshold of 30 days or more produces a notice at every normal renewal cycle and teaches people to ignore it.
- It also notices a certificate that does not match, such as a wrong host name or an incomplete chain. Expiry is the most common failure, not the only one.
- It does not depend on the server it checks. A cron job on the same machine fails together with that machine. For the reasoning behind checking from several places, see uptime monitoring from multiple locations.
If you write your own script around -checkend, monitor the script as well. A check that silently stops running is worse than none; the heartbeat pattern for cron jobs covers that.
Common mistakes
- Monitoring only the main domain. Subdomains, the
wwwvariant, mail servers and API hosts each have their own certificate or their own entry in one. - Forgetting certificates that are not renewed automatically. Purchased certificates with a one-year lifetime, certificates on appliances, and internal certificate authorities expire rarely enough that nobody remembers how to renew them.
- Testing without SNI, or against an IP address, and getting the default certificate.
- Alerting only on the day of expiry. Then the alert and the outage arrive together.
- Treating the alert as noise. A certificate warning is rare and always actionable, so it should reach a person. How to keep such alerts meaningful is covered in alert fatigue, quiet hours and escalation.
Checklist
- List every host name that serves TLS, including
www, mail and API hosts. - Check each one with
openssl s_client -servernameand note thenotAfterdate. - Confirm the renewal timer exists:
systemctl list-timers certbot.timer. - Run
sudo certbot renew --dry-runand fix whatever it reports. - Add a deploy hook that reloads the web server.
- Set up an outside check per host name with a warning at about 14 days remaining.
- Put manually renewed certificates in a calendar with the name of the person who renews them.
How Lynx Heartbeat helps
Lynx Heartbeat checks certificate expiry as part of its outside checks. It opens a TLS connection with the host name as SNI and evaluates the certificate that is actually served, not a file on disk, so a renewal that never reached the web server is noticed. The warning arrives through the channels you set up, such as email, Telegram, Slack or Microsoft Teams. Domain registration expiry is a separate check type in the same place. An overview of all outside checks is on the features page.
Frequently asked questions
How do I check when a TLS certificate expires?
Connect to the server and read the certificate it serves: echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate. The notAfter line is the expiry date.
Why did my certificate expire although certbot renews automatically?
Usually for one of three reasons: the renewal timer does not run, the validation fails (port 80 blocked, DNS changed, expired DNS API token), or the certificate was renewed on disk but the web server was never reloaded and still serves the old one.
How many days before expiry should I be alerted?
For 90-day certificates that renew about 30 days before expiry, a warning at 14 days remaining and a critical alert at a few days remaining works well. At 14 days the renewal has already failed for two weeks, and you still have time to fix it.
Does Let's Encrypt still send expiry warning e-mails?
No. Let's Encrypt ended its expiry notification e-mails in June 2025. If you relied on those messages, you need your own monitoring.
Is it enough to check the certificate file on the server?
No. The file can be fresh while the running web server still holds the old certificate in memory, or while a load balancer or CDN in front serves a different one. Only a TLS connection from the outside shows what visitors get.