在 Linux 下使用 OpenSSL 查看证书,常见场景有几种,下面按最常用的方式给你总结。
openssl x509 -in certificate.crt -text -noout
说明:
-in:证书文件-text:以可读文本显示-noout:不输出原始编码内容示例输出包含:
openssl x509 -in certificate.crt -noout -fingerprint
指定哈希算法:
openssl x509 -in certificate.crt -noout -fingerprint -sha256
openssl x509 -in certificate.crt -noout -dates
输出示例:
notBefore=Jan 1 00:00:00 2024 GMT
notAfter=Dec 31 23:59:59 2024 GMT
openssl x509 -in certificate.crt -noout -ext subjectAltName
openssl x509 -in certificate.crt -noout -text | grep "Signature Algorithm"
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -text
只看关键信息:
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates -subject -issuer
openssl pkcs12 -info -in cert.p12
openssl req -in request.csr -text -noout
openssl rsa -in private.key -check -noout
如果你愿意,可以告诉我:
我可以直接给你最合适的一条命令。