How to Check SSL Certificate Expiry with OpenSSL
To see when a site certificate expires, run echo | openssl s_client -servername SITE -connect SITE:443 2>/dev/null | openssl x509 -noout -dates. Read notAfter. Renew with Certbot before that date. Checking expiry is read-only and safe on public HTTPS sites you administer.
Quick answer
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates -subject -issuerWhy check expiry?
An expired certificate breaks trust. Customers leave. Apps fail health checks. Fatima in Dubai and Vivek in Indore both lost a morning to a silent expiry. One command would have warned them.
What are you reading?
A public HTTPS site presents an X.509 certificate. notBefore and notAfter are the validity window. OpenSSL can print them without changing anything on the server.
How do I check step by step?
- Choose the live hostname you manage, for example
shop.example.com. - Fetch and print dates:
echo | openssl s_client -servername shop.example.com -connect shop.example.com:443 2>/dev/null | openssl x509 -noout -dates -subjectsubject=CN = shop.example.com notBefore=Aug 1 00:00:00 2026 GMT notAfter=Oct 30 00:00:00 2026 GMTWhat it means: This cert ends 30 Oct 2026 UTC. Plan renew before that day.
- Check a PEM file on the server (after Certbot):
sudo openssl x509 -in /etc/letsencrypt/live/shop.example.com/fullchain.pem -noout -enddateWhat it means: Reads the file Certbot stored. Useful when DNS is temporarily wrong.
- See days left (GNU date example):
end=$(echo | openssl s_client -servername shop.example.com -connect shop.example.com:443 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) date -d "$end" +%s # then compare to nowWhat it means: Scripting the end date lets cron warn you.
- Renew early:
sudo certbot renew --dry-runthen real renew on a timer.
Ravindra Bagale's Tip
Set a calendar alert 21 days before notAfter. Let's Encrypt certs last about 90 days. Meera in Hyderabad automates this with a tiny cron that emails the team if fewer than 20 days remain.
Ravindra Bagale's Tip – मराठी
notAfter पेक्षा 21 दिवस आधी calendar alert ठेवा. Let's Encrypt सुमारे 90 दिवस चालते. हैदराबादमधील मीरा cron ने टीमला email करते जर 20 दिवसांपेक्षा कमी शिल्लक असतील.
Ravindra Bagale's Tip – हिंदी
notAfter से 21 दिन पहले calendar alert लगाओ। Let's Encrypt लगभग 90 दिन चलता है। हैदराबाद की मीरा cron से टीम को email करती है अगर 20 दिन से कम बचे हों।
Quick quiz: check what you learned
Which openssl field shows when a certificate expires?
- notAfter date in the certificate
- notCool field in the certificate
- TTL value from a dig query
- MX record from DNS lookup
Show answer
A. notAfter is the expiry timestamp openssl x509 prints.
Why pass -servername when checking a shared HTTPS host?
- So SNI returns the correct virtual-host certificate
- So you can hack the certificate authority
- So you can skip DNS resolution entirely
- So you can force the server onto plain HTTP
Show answer
A. SNI selects which certificate the server presents.
When should you renew a Let's Encrypt certificate?
- Days before notAfter, via automated renew
- One full year after the cert expires
- Never renew; wait for browsers to fail
- Only on Fridays during maintenance
Show answer
A. Automate renew a few days before expiry.
Learn it properly
This guide is the short path. These pages go deeper, with labs:
Frequently asked questions
What is the openssl command to check certificate expiry?
echo | openssl s_client -servername SITE -connect SITE:443 2>/dev/null | openssl x509 -noout -enddate
What does notAfter mean?
The last moment the certificate should be trusted. After that, browsers show a warning.
Does this work for IP addresses?
TLS usually needs a hostname (SNI). Prefer the DNS name.
How is this different from installing a cert?
This guide only reads expiry. Installing is covered in the Certbot on EC2 guide.
Can I check a local PEM file?
Yes: openssl x509 -in fullchain.pem -noout -dates