
How to Check an SSL Certificate's Expiration Date
by Leo Almeida · Published · 3 minute read
Check when a TLS certificate expires with openssl, curl, a browser or an online SSL checker, check certificate files on disk, and script an expiry check for a list of hosts.
Checking a certificate's expiry date takes seconds. Getting the right answer takes a little more care: you want the certificate the host actually serves to clients, on the right port and for the right hostname, not the file you think is deployed.
Option 1: An Online SSL Checker
The quickest way for a public host is the free ElevenGuard SSL checker. Enter the hostname and you get the expiry date and days left, the issuer, whether the chain is trusted, and an A–F grade of the TLS configuration. It connects from the internet, so it sees what your users see.
Option 2: openssl s_client
On any machine with OpenSSL:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -datesThe output includes notBefore and notAfter, the start and end of validity:
subject=CN=example.com
issuer=C=US, O=Let's Encrypt, CN=R11
notBefore=Oct 1 08:12:44 2026 GMT
notAfter=Dec 30 08:12:43 2026 GMTTwo details matter:
- Always pass
-servername. It sends SNI, the hostname, in the handshake. Without it, a server or CDN hosting many names may return a default certificate for a different host, and you check the wrong expiry date. - Use the real port. Mail and other services use TLS on other ports:
-connect mail.example.com:465for SMTPS, or add-starttls smtpwith port 25 or 587.
Option 3: Fail If It Expires Soon
-checkend takes a number of seconds and exits non-zero if the certificate expires within that window. That makes it easy to use in scripts and CI:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -checkend $((14*86400)) \
&& echo "OK for 14+ days" || echo "Expires within 14 days"Option 4: curl
curl prints the certificate details in verbose mode:
curl -svo /dev/null https://example.com 2>&1 | grep -iE "expire date|issuer|subject:"The exact lines depend on the TLS library curl was built with, but most builds show expire date. curl also fails the request if the chain doesn't verify, which catches missing intermediates that some browsers hide.
Option 5: A Certificate File on Disk
For a PEM file, for example on the server itself:
openssl x509 -in /etc/letsencrypt/live/example.com/fullchain.pem -noout -enddateFor Certbot specifically, sudo certbot certificates lists every certificate it manages with its expiry date and days left.
Remember that a file on disk is not proof of what the host serves. If the web server was never reloaded after renewal, the file is new and the served certificate is old. Check both when debugging a renewal.
In a Browser
Click the icon left of the address bar, open the connection or certificate details, and look for "Valid to" or "Expires on". This is fine for one host, but browsers cache connections and may repair an incomplete chain from their own cache, so the result can differ from what an API client sees.
Checking a List of Hosts
A small loop covers a handful of hosts:
for host in example.com api.example.com mail.example.com; do
end=$(echo | openssl s_client -connect "$host:443" -servername "$host" 2>/dev/null \
| openssl x509 -noout -enddate | cut -d= -f2)
echo "$host $end"
doneRun it from cron and you have basic monitoring. It also inherits the usual problems: the host list goes stale, fixed thresholds don't fit short-lived certificates, and nobody notices when the cron job itself stops. The SSL certificate monitoring guide covers what a full setup should check, and ElevenGuard certificate monitoring runs the check daily for every host with alerts by email or Slack.
Common Mistakes
- No SNI, so the check returns a default certificate for another name.
- Checking only port 443 when the service that expired was SMTP, IMAP or an admin port.
- Checking one backend behind a load balancer when another backend still serves the old certificate.
- Trusting the file on disk instead of the handshake.
- Reading local time as UTC.
notAfteris in GMT.
