在 Linux 下用 OpenSSL 验证证书,常见场景和命令如下(从最常用到进阶):
openssl verify -CAfile ca.crt server.crt
✅ 成功示例:
server.crt: OK
❌ 失败示例:
error 20 at 0 depth lookup: unable to get local issuer certificate
cat intermediate.crt ca.crt > fullchain.crt
openssl verify -CAfile fullchain.crt server.crt
openssl x509 -noout -modulus -in server.crt | md5sum
openssl rsa -noout -modulus -in server.key | md5sum
✅ 两个值 完全一致 才说明匹配
openssl x509 -in server.crt -noout -dates
输出示例:
notBefore=May 10 00:00:00 2024 GMT
notAfter=May 10 00:00:00 2025 GMT
openssl x509 -in server.crt -noout -text | grep -A1 "Key Usage"
常见用途:
Digital SignatureKey EnciphermentTLS Web Server Authenticationopenssl s_client -connect example.com:443 -showcerts
只看验证结果:
openssl s_client -connect example.com:443 -CAfile /etc/ssl/certs/ca-certificates.crt
openssl crl2pkcs7 -nocrl -certfile server.crt \
-certfile intermediate.crt | openssl pkcs7 -print_certs -noout
openssl ocsp -issuer ca.crt \
-cert server.crt \
-url http://ocsp.example.com
| 错误 | 含义 |
|---|---|
| error 20 | 找不到签发 CA |
| error 10 | 证书已过期 |
| error 7 | 证书签名无效 |
| error 21 | 用途不匹配 |
✅ 证书未过期
✅ CA 可信
✅ 证书链完整
✅ 私钥匹配
✅ 用途正确
如果你愿意,可以把 具体报错信息或证书类型(Nginx / HTTPS / 自签 / K8s / 双向 TLS)发出来,我可以帮你精确分析。