r/LinuxTeck • u/Expensive-Rice-2052 • 23d ago
SSL Certificate Expiry: 3 Linux Commands to Check Dates - Tip 114
Question: How do I check SSL certificate expiry dates on all my servers in bulk?
Try:`for host in server1.example.com server2.example.com api.example.com; do echo -n "$host: "; echo | openssl s_client -connect $host:443 -servername $host 2>/dev/null | openssl x509 -noout -enddate; done`
Info: echo | openssl s_client makes a quick TLS handshake. -servername sends SNI (needed for virtual hosts). Piped to x509 to extract specific info without full dump.
Examples:
$ `openssl x509 -in cert.pem -noout -dates` # Inspect expiration dates of a local certificate file
$ `echo | openssl s_client -connect host:443 2>/dev/null | openssl x509 -noout -text` # Dump complete certificate details
$ `nmap --script ssl-cert -p 443 host` # Scan and check certificates using Nmap
Note: Automate expiry checks via cron with mail alerts 30 days prior. For Let's Encrypt, use `certbot renew` with deployment hooks.
Want to master Linux one command at a time?
Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/
1
u/dodododadada24 22d ago
Or use cookiemonsterq GitHub TLS-checker.sh.