查看网站证书的过期时间
用 openssl s_client 配合 x509 -dates 命令,直接打印网站 TLS 证书的生效和过期日期。
运行上面的管道命令,看 notAfter 那一行就是证书过期时间,对照今天的日期即可判断。
01命令
命令
$ echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates02作用说明
这条命令先连上网站的 443 端口拿到对方证书,然后只打印有效期,省去一大堆无关输出。如果你信任的网站突然提示"证书不受信任",先看看是不是证书真的过期了。只想要过期时间可以改用 `-endDate`;检查本地保存的证书文件则用 `openssl x509 -in cert.pem -noout -dates`。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- openssl — cryptography toolkit (macOS man page)依据: Documents openssl s_client for connecting to a TLS server and x509 -noout -dates for printing a certificate's validity window.
最后验证: 2026-09-18 · 分类: 安全与隐私