How to monitor SSL certificate expiration (OpenSSL, cron and alerts)
TL;DR: Check a certificate's expiry with openssl s_client -connect host:443 -servername host | openssl x509 -noout -enddate, test a threshold with -checkend, and run a daily cron job that emails you when fewer than 21 days remain. Monitoring services can also check SSL and alert you. Even with auto-renewal, monitor, because renewals fail silently when DNS changes, ports close or a cron job stops. Certificate lifetimes are getting shorter, so checks matter more every year.
Why monitor if renewal is automatic?
Auto-renewal fails more often than people expect: a changed DNS record, a blocked validation path, a stopped renew timer or a hosting migration. The first sign is a browser warning for visitors. See Certbot auto-renewal setup and what shorter certificate lifetimes mean.
Check the expiry date manually
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -enddate
Output looks like notAfter=Mar 10 12:00:00 2027 GMT. In a browser, click the padlock and view the certificate.
Check whether it expires within N days
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
| openssl x509 -noout -checkend 1814400 \
&& echo OK || echo "Expires within 21 days"
1814400 seconds equals 21 days.
A daily cron script
#!/bin/bash
for d in example.com shop.example.com; do
if ! echo | openssl s_client -connect $d:443 -servername $d 2>/dev/null \
| openssl x509 -noout -checkend 1814400 >/dev/null; then
echo "SSL for $d expires within 21 days" | mail -s "SSL expiry: $d" [email protected]
fi
done
Run it daily from cron. Make sure the server can send mail. See WordPress cron jobs for how scheduled tasks can fail.
Use a monitoring service
Uptime tools can check SSL validity and send alerts by email, SMS or chat. Read uptime monitoring you can trust and get alerted before customers do.
When an alert fires
- Check the renewal logs and the renewal timer.
- Confirm DNS and the validation path are reachable.
- Renew manually and reload the web server.
- Test the site and any subdomains and mail ports that use the certificate.
FAQs
How do I check when an SSL certificate expires?
Use the browser padlock or the openssl command with -enddate.
How often should I check?
Daily is enough for most sites.
How many days before expiry should I be alerted?
Many teams use 21 and 7 days.
Why did my auto-renewal fail?
DNS or validation changes, a stopped timer or a server migration are common causes.
Do I need to monitor subdomains?
Yes, each hostname can have its own certificate.
Can monitoring check mail server certificates?
Yes, use the SMTP or IMAP port with -starttls in openssl.
Is a wildcard certificate monitored the same way?
Yes, check one hostname that uses it.
What happens if a certificate expires?
Browsers show a warning and many visitors leave.
Conclusion
Treat certificate expiry like any other outage risk. Check dates with OpenSSL, schedule a daily threshold check and add an external monitor so you hear about a failed renewal before your visitors do.
HostCloud helps Indian websites with reliable hosting, domains and support. See the options at https://hostcloud.in.
Sources: