You can check SSL certificate expiry for any website from a terminal with one openssl command. It needs no login to the server and no browser. This guide shows that command, a shorter one for scripts, a small script that checks many sites, and how to make sure a certificate never runs out without anyone noticing.
The commands were run in our lab on Ubuntu 24.04 with OpenSSL 3 in November 2026, against a test web server with a 20-day certificate. The outputs are real.
The short answer
echo | openssl s_client -connect yourcompany.com:443 -servername yourcompany.com 2>/dev/null | openssl x509 -noout -datesThe line that starts with notAfter= is the expiry date. Replace the domain in both places.
Check SSL certificate expiry on a live site
The same command with the subject and issuer added:
echo | openssl s_client -connect lab.example.test:443 -servername lab.example.test 2>/dev/null | openssl x509 -noout -subject -issuer -datessubject=CN = lab.example.test
issuer=CN = lab.example.test
notBefore=Nov 13 16:06:17 2026 GMT
notAfter=Dec 3 16:06:17 2026 GMTWhat each part does:
openssl s_client -connect host:443opens a TLS connection and prints the certificate the server sends.-servernamesends the host name (SNI). Leave it out and a server that hosts several sites may hand you the wrong certificate.echo |closes the connection straight away so the command does not wait for input.openssl x509 -noout -datesreads the certificate and prints only its two dates.
Dates are in GMT. For India, add five and a half hours.
Other ports work the same way. For a mail server that uses STARTTLS:
echo | openssl s_client -connect mail.yourcompany.com:587 -starttls smtp 2>/dev/null | openssl x509 -noout -datesA yes or no answer for scripts
-checkend takes a number of seconds and tells you whether the certificate will still be valid after that time. 2592000 seconds is 30 days, 604800 is 7 days.
echo | openssl s_client -connect lab.example.test:443 -servername lab.example.test 2>/dev/null | openssl x509 -noout -checkend 2592000
echo "exit code: $?"Certificate will expire
exit code: 1With 7 days in place of 30:
Certificate will not expire
exit code: 0Our lab certificate had 19 days left, so it fails the 30-day test and passes the 7-day one. The exit code is what a monitoring script should read.
The same check with curl
curl -vI https://yourcompany.com 2>&1 | grep -E 'start date|expire date|subject:|issuer:'* subject: CN=lab.example.test
* start date: Nov 13 16:06:17 2026 GMT
* expire date: Dec 3 16:06:17 2026 GMT
* issuer: CN=lab.example.testCheck a certificate file on the server
If you are logged in to the server, read the file itself:
sudo openssl x509 -in /etc/letsencrypt/live/yourcompany.com/fullchain.pem -noout -enddateThe file on disk and the certificate the web server presents can differ. A renewed file does nothing until the web server reloads, so always confirm with the live check as well.
A script for many sites
Save this as certdays.sh and make it executable with chmod +x certdays.sh.
#!/bin/bash
# usage: ./certdays.sh host1 host2 ...
for host in "$@"; do
end=$(echo | openssl s_client -connect "$host:443" -servername "$host" 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
if [ -z "$end" ]; then echo "$host: no certificate read"; continue; fi
days=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 ))
echo "$host: $days days left (expires $end)"
done./certdays.sh lab.example.test 192.0.2.1lab.example.test: 19 days left (expires Dec 3 16:06:17 2026 GMT)
192.0.2.1: no certificate readThe second address has no web server, to show what a failed lookup prints. Put the script in cron once a day and have it mail you when a number drops below 20. It uses GNU date, so it runs on Linux as written and needs a small change on macOS.
Why certificates expire sooner than they used to
Browser makers and certificate authorities agreed in April 2025 to shorten certificate lifetimes in steps. A certificate issued today can be valid for 200 days at most.
| Issued on or after | Longest validity |
|---|---|
| 15 March 2026 | 200 days |
| 15 March 2027 | 100 days |
| 15 March 2029 | 47 days |
A certificate bought “for a year” is now reissued during that year, and from 2029 it will be replaced about every six weeks. Renewing by hand does not scale to that, so renewal has to be automatic.
Stop certificates expiring
- Use automatic renewal. With Let’s Encrypt and Certbot,
sudo certbot renew --dry-runtests the renewal without changing anything, andsystemctl list-timers | grep certbotshows whether the timer is active. These two lines are from the Certbot documentation and were not run in our lab. - Make sure the web server reloads after a renewal. Certbot’s
--deploy-hook "systemctl reload nginx"does that. - Monitor from outside. The script above, run from a different machine, catches the cases automation misses: a failed renewal, a server that did not reload, a certificate on a load balancer that nobody remembered.
- Keep a list of every certificate you own, including mail servers, VPN gateways and admin panels on unusual ports. The forgotten ones are the ones that expire.
When a certificate does expire, browsers show a full-page warning, apps and payment callbacks that connect to your server start failing, and some customers will not come back.
Free tool: our website safety check tests your certificate, HTTPS redirect and security headers from the outside and grades the site in about 30 seconds. Of the first 10 sites checked with it, 2 failed the certificate test.
Related guides
- Secure Nginx Configuration for Production
- How to Check Open Ports on Linux
- Web Application VAPT: Scope, Steps and Report
Sources
- OpenSSL documentation: openssl-s_client
- OpenSSL documentation: openssl-x509
- DNSimple: SSL certificate validity changes, 2026 to 2029
- Certbot user guide: renewing certificates
Need a full check of what your servers expose? Our VAPT services cover TLS settings, exposed services and web application testing. Contact us for a quote.
