openssl s_client 是 OpenSSL 工具包中用于测试 SSL/TLS 连接的强大命令行工具。它常用于调试 HTTPS 网站、检查服务器证书、验证加密套件支持等场景。
最简单的用法是连接一个 HTTPS 站点:
openssl s_client -connect example.com:443
-connect host:port:指定要连接的主机和端口(默认443)-servername example.com:启用 SNI(Server Name Indication)-showcerts:显示完整的证书链-CAfile file.pem:指定信任的 CA 证书文件-tls1_2 / -tls1_3:强制使用特定 TLS 版本openssl s_client -connect www.example.com:443 -servername www.example.com -showcerts
执行后,终端会输出 TLS 握手详情、服务器证书以及连接状态。
你可以将输出通过管道传递给 openssl x509 来格式化证书:
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
上述命令可快速查看证书的有效期。
该工具非常适合 Web 开发者、系统管理员、网络安全工程师在排查 SSL/TLS 相关问题时使用。