An expired TLS certificate turns your site into a full-page browser warning. It is also one of the easiest outages to prevent, because the expiry date is public. Here is how to read it in a few seconds, from the command line or from a script.

1. Read the expiry date with OpenSSL

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

Output looks like notAfter=Mar 3 09:12:44 2027 GMT. The -servername flag matters: without it, a server hosting several sites may return the wrong certificate.

2. Get the number of days left

end=$(echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null \ | openssl x509 -noout -enddate | cut -d= -f2) echo $(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 )) days left 

On macOS, replace date -d "$end" +%s with date -j -f "%b %e %T %Y %Z" "$end" +%s.

openssl can also answer a yes/no question directly: openssl x509 -checkend 1209600 exits with status 1 if the certificate expires within 14 days (1,209,600 seconds).

3. Check every host you own, not only the website

The certificates that expire unnoticed are rarely on the main site. Check each of these:

  • mail.example.com on port 443, 465 or 993
  • staging, admin and API subdomains
  • certificates served by a CDN or a load balancer, which can differ from the one on your origin
  • anything on a non-standard port: -connect host:8443

For SMTP with STARTTLS: openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com.

4. Turn it into a cron check

#!/bin/sh for h in example.com www.example.com mail.example.com; do echo | openssl s_client -servername "$h" -connect "$h:443" 2>/dev/null \ | openssl x509 -noout -checkend 1209600 >/dev/null \ || echo "$h: certificate expires in less than 14 days (or is unreachable)" done 

Run it daily and send the output to an address you actually read. Two weeks is long enough to react on a weekend.

5. If it keeps happening, fix renewal, not the reminder

  • With Let's Encrypt and certbot, test renewal with certbot renew --dry-run, and check systemctl list-timers | grep certbot.
  • A renewal that works but is never reloaded by the web server is a classic: add a deploy hook such as --deploy-hook "systemctl reload nginx".
  • Certificate lifetimes are getting shorter (100 days maximum from March 15, 2027), so manual renewal gets harder every year.

No terminal at hand?

AttackScout has a free SSL certificate check: enter a domain and it shows the expiry date, the issuer and the chain.