Checking SSL certificate health from the command line is essential for maintaining secure website operations and preventing unexpected certificate-related outages. System administrators and DevOps engineers regularly need quick, reliable methods to verify certificate status, expiration dates, and security configurations without relying on web-based tools or browser interfaces.
Command-line SSL certificate checking provides immediate insights into certificate validity, chain completeness, cipher strength, and protocol support. These tools become invaluable during incident response, routine maintenance, and automated monitoring workflows.
Essential OpenSSL Commands for Certificate Health Checks
OpenSSL remains the most versatile tool for SSL certificate analysis. The basic connection test reveals fundamental certificate information and identifies immediate issues.
“`
openssl s_client -connect example.com:443 -servername example.com
“`
This command establishes a connection and displays the complete certificate chain, validity dates, and supported cipher suites. The `-servername` parameter enables SNI (Server Name Indication), crucial for servers hosting multiple SSL certificates.
For automated scripts, add `-verify_return_error` to ensure the command exits with an error code when certificate validation fails. This approach enables reliable certificate health monitoring within larger automation workflows.
The certificate expiration check extracts specific validity information:
“`
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates
“`
This one-liner filters the output to show only the “notBefore” and “notAfter” dates, making it perfect for scripting and alerting systems.
Advanced Certificate Chain Verification
Certificate chain issues cause significant SSL problems, yet many administrators overlook proper chain validation. Incomplete chains trigger browser warnings and API connection failures, even when the primary certificate remains valid.
The following command downloads and verifies the entire certificate chain:
“`
openssl s_client -connect example.com:443 -servername example.com -showcerts
“`
This reveals each certificate in the chain, including intermediate certificates. Missing intermediate certificates represent a common configuration error that affects older browsers and some API clients disproportionately.
For deeper chain analysis, extract each certificate and verify the chain manually:
“`
echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null | awk ‘/BEGIN CERTIFICATE/,/END CERTIFICATE/{print}’
“`
Save each certificate block to separate files and verify the chain structure using `openssl verify` commands.
Protocol and Cipher Suite Analysis
Modern SSL certificate health extends beyond certificate validity to include protocol support and cipher strength. Weak cipher suites expose websites to various attacks, making regular cipher analysis essential.
Test specific TLS versions with targeted connection attempts:
“`
openssl s_client -connect example.com:443 -tls1_2 -servername example.com
openssl s_client -connect example.com:443 -tls1_3 -servername example.com
“`
These commands verify protocol support and reveal which cipher suites the server negotiates for each TLS version.
The cipher suite analysis becomes particularly important for compliance requirements. Many organizations must disable weak ciphers to meet security standards, yet configuration changes sometimes inadvertently enable deprecated ciphers.
Consider the scenario where a load balancer configuration update accidentally enables SSLv3 support. Regular command-line testing would catch this regression before it creates compliance violations or security vulnerabilities.
Automated Certificate Monitoring Scripts
Effective certificate health monitoring requires automation. Manual checks don’t scale across multiple domains and often miss critical expiration windows.
Create a simple monitoring script that checks multiple domains:
“`bash
#!/bin/bash
DOMAINS=”example.com api.example.com cdn.example.com”
WARNING_DAYS=30
for domain in $DOMAINS; do
expiry=$(echo | openssl s_client -connect $domain:443 -servername $domain 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
expiry_epoch=$(date -d “$expiry” +%s)
current_epoch=$(date +%s)
days_until_expiry=$(( ($expiry_epoch – $current_epoch) / 86400 ))
if [ $days_until_expiry -lt $WARNING_DAYS ]; then
echo “WARNING: $domain certificate expires in $days_until_expiry days”
fi
done
“`
This script checks multiple domains and alerts when certificates approach expiration. Integrate it with cron jobs for regular automated monitoring.
Advanced monitoring scripts should also verify cipher suite strength and check for common misconfigurations that affect certificate health.
Common Certificate Health Misconceptions
Many administrators believe that certificate monitoring only involves checking expiration dates. This misconception leads to overlooked security issues and unexpected SSL failures.
Certificate health encompasses multiple factors: chain completeness, revocation status, cipher suite support, and protocol compatibility. A certificate might remain technically valid while presenting serious security risks through weak cipher support or incomplete chains.
Another widespread myth suggests that wildcard certificates eliminate the need for detailed monitoring. Wildcard certificates require the same vigilant monitoring as single-domain certificates, plus additional attention to subdomain coverage and potential security implications.
OCSP (Online Certificate Status Protocol) checking represents another frequently ignored aspect of certificate health. Revoked certificates continue to show valid expiration dates, yet browsers and security-conscious clients reject them immediately.
Check OCSP status using:
“`
openssl s_client -connect example.com:443 -servername example.com -status
“`
This command includes OCSP stapling information in the output, revealing the certificate’s revocation status.
Integration with Monitoring Infrastructure
Command-line certificate checking integrates seamlessly with existing monitoring infrastructure. Popular monitoring systems like Nagios, Zabbix, and Prometheus support custom scripts for SSL certificate health checks.
Design monitoring scripts with appropriate exit codes and structured output for integration with alerting systems. Use JSON output format for complex monitoring data that requires parsing by multiple systems.
For large network environments, implement distributed certificate checking that tests certificates from multiple geographic locations. Certificate health can vary based on CDN configuration and regional certificate deployment.
The monitoring approach should account for certificate renewal workflows. Some organizations experience monitoring alert fatigue because their systems generate warnings during planned certificate renewals. Design scripts that recognize renewal windows and adjust alerting accordingly.
Troubleshooting Certificate Issues via Command Line
Command-line tools excel at diagnosing SSL certificate problems that web-based checkers might miss. Network-level issues, firewall configurations, and server-specific SSL implementations require direct connection testing.
When investigating certificate problems, test from multiple network locations:
“`
openssl s_client -connect example.com:443 -servername example.com -verify 5 -CApath /etc/ssl/certs/
“`
The `-verify 5` parameter sets the verification depth, while `-CApath` specifies the certificate authority bundle location. These options help identify trust chain issues specific to certain environments.
For certificates behind load balancers or CDNs, test individual backend servers when possible:
“`
openssl s_client -connect 192.168.1.100:443 -servername example.com
“`
This approach bypasses load balancing and reveals server-specific certificate configurations that might cause intermittent issues.
The combination of systematic command-line testing and proper monitoring during infrastructure changes prevents most SSL-related outages before they impact users.
FAQ
How often should I check SSL certificate health from the command line?
Check certificate health daily for critical systems and weekly for less critical domains. Automated scripts should run more frequently – every few hours – to catch issues quickly. Manual command-line checks become necessary during troubleshooting or after configuration changes.
Can command-line tools detect all SSL certificate problems?
Command-line tools detect most certificate issues including expiration, chain problems, cipher weaknesses, and basic connectivity. However, they might miss browser-specific compatibility issues, mixed content problems, or certificate transparency violations that require specialized testing approaches.
What’s the difference between checking certificates with OpenSSL versus curl?
OpenSSL provides detailed certificate analysis and supports extensive configuration options for thorough testing. Curl offers simpler certificate checking suitable for basic connectivity verification but lacks the depth needed for comprehensive certificate health analysis. Use OpenSSL for detailed investigation and curl for quick connectivity tests.
Implementing Regular Certificate Health Monitoring
Command-line SSL certificate health checking forms the foundation of robust certificate management. Regular automated checking prevents certificate-related outages and maintains security compliance across your infrastructure.
Combine daily automated scripts with weekly manual verification using OpenSSL commands. This approach catches both gradual certificate health degradation and sudden configuration issues that could compromise website security.
Integrate command-line certificate checking into your incident response procedures and change management workflows. The immediate feedback and detailed analysis capabilities make these tools indispensable for maintaining SSL certificate health at scale.
