保护您的 Linux 服务器: 如何检查 TLS/SSL 证书到期日期. 在本文中, 我们将学习如何使用OpenSSL客户端从命令行中检查SSL/TLS证书的到期日期. OpenSSL客户端提供有关有效性日期的详细信息, 有效期, 及证书颁发机构.
检查 SSL/TLS 证书的到期日期, 打开终端应用程序并运行以下命令:
openssl s_client -servername {SERVER_NAME} -connect {SERVER_NAME}:{PORT} | openssl x509 -noout -dates
For example, 找出 证书的有效期 for 进入init.com, run the following command:
DOM="enterinit.com"
PORT="443"
openssl s_client -servername $DOM -connect $DOM:$PORT | openssl x509 -noout -dates
输出将包括有关证书的开始日期和到期日期的信息.
您可以添加 echo
命令以避免按下 CTRL+C
, 如下图:
DOM="{SITE_URL}"
PORT="443"
echo | openssl s_client -servername $DOM -connect $DOM:$PORT | openssl x509 -noout -dates
The openssl
上述命令使用的命令行选项如下:
s_client
: 实现使用 SSL/TLS 连接到远程主机的通用 SSL/TLS 客户端.-servername $DOM
: 设置 TLS SNI (服务器名称指示) 将 ClientHello 消息中的扩展扩展为给定值.-connect $DOM:$PORT
: 指定主机 ($DOM) 和可选端口 ($港口) to connect to.x509
: 运行证书显示和签名实用程序.-noout
: 防止输出证书的编码版本.-dates: Prints out the start and expiry dates of a TLS or SSL certificate.
找出 PEM 编码的证书文件的到期日期, run the following command:
openssl x509 -enddate -noout -in {/path/to/my/my.pem}
For example, 找出证书的到期日期 进入init.com, run the following command:
openssl x509 -enddate -noout -in /etc/nginx/ssl/enterinit.com
输出将包括证书的到期日期.
您还可以检查证书是否会在给定时间范围内过期. For example, 查看证书是否会在接下来的 7 天内过期, run the following command:
openssl x509 -enddate -noout -in my.pem -checkend 604800
检查证书是否会在接下来的四个月内过期, run the following command:
openssl x509 -enddate -noout -in my.pem -checkend 10520000
总之, OpenSSL是一个强大的诊断工具,可提供有关SSL/TLS证书的有用信息. 它可以帮助您确保证书有效且是最新的, 并在必要时及时采取行动.