The Script
echo | openssl s_client -connect YOUR_DOMAIN:443 2>/dev/null | openssl x509 -noout -dates
Explanation
openssl s_client -connect YOUR_DOMAIN:443
– This connects to the server on port 443 which is the default for HTTPS, and fetches the SSL certificate
2>/dev/null
– This discards any error messages to keep the output clean
openssl x509 -noout -dates
– This extracts the validity dates from the fetched certificate
Variations
- To view the entire certificate
echo | openssl s_client -connect YOUR_DOMAIN:443 2>/dev/null | openssl x509 -noout -text
- To check a certificate on a different port (ex., 8443)
echo | openssl s_client -connect YOUR_DOMAIN:8443 2>/dev/null | openssl x509 -noout -dates
- To check the certificate chain (to see intermediate certificates)
echo | openssl s_client -connect YOUR_DOMAIN:443 -showcerts 2>/dev/null