温馨提示×

linux openssl怎么排查错误

小樊
41
2026-10-16 06:45:32
栏目: 云计算

在 Linux 下使用 OpenSSL 时,排查错误通常可以从命令返回信息、错误码、日志、配置、证书本身几个层面入手。下面给你一套实用的排查思路和常见方法。


一、先看 OpenSSL 自己的错误信息

1. 直接看命令输出

OpenSSL 命令失败通常会直接打印错误,例如:

openssl s_client -connect example.com:443

常见错误:

  • connect: Connection refused → 网络/端口问题
  • SSL routines:SSL23_GET_SERVER_HELLO: → 协议/加密套件不匹配
  • certificate verify failed → 证书校验失败

2. 使用 openssl errstr 解析错误码

OpenSSL 有时会输出类似:

error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

可以用:

openssl errstr 1416F086

输出示例:

error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

二、排查网络连接问题

1. 检查端口是否通

telnet example.com 443
# 或
nc -vz example.com 443

不通的情况:

  • 防火墙
  • 服务未启动
  • 安全组限制

2. 使用 s_client 看握手过程

openssl s_client -connect example.com:443 -debug

或:

openssl s_client -connect example.com:443 -state

重点看:

  • 是否完成握手
  • 服务器证书是否返回
  • 协议版本(TLS1.2 / TLS1.3)

三、证书相关问题排查

1. 验证证书是否有效

openssl verify -CAfile ca.pem server.crt

常见错误:

  • unable to get local issuer certificate → 缺少 CA
  • certificate has expired → 证书过期
  • hostname mismatch → 域名不匹配

2. 查看证书详细信息

openssl x509 -in server.crt -noout -text

重点检查:

  • Not Before / Not After
  • Subject / SAN
  • Issuer

3. 检查私钥和证书是否匹配

openssl x509 -noout -modulus -in server.crt | openssl md5
openssl rsa -noout -modulus -in server.key | openssl md5

两个 md5 必须一致。


四、协议 / 加密套件问题

1. 指定协议测试

openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3

2. 查看支持的加密套件

openssl ciphers -v

五、OpenSSL 配置问题

1. 查看 OpenSSL 版本

openssl version

不同版本对 TLS / 算法支持不同(尤其是 1.0.2 / 1.1.1 / 3.0)。


2. 检查 openssl.cnf

路径通常是:

/etc/ssl/openssl.cnf

常见问题:

  • 禁用了某些协议
  • 指定了错误的默认 CA

六、系统层面排查

1. 查看系统日志

journalctl -u nginx
# 或
tail -f /var/log/syslog

2. 检查 CA 证书库

ls /etc/ssl/certs/

更新 CA:

update-ca-certificates

七、常见错误速查表

错误 原因
certificate verify failed CA 缺失 / 证书链不完整
unknown protocol 端口不是 HTTPS
no shared cipher 加密套件不匹配
self signed certificate 自签名未信任
SSL23_GET_SERVER_HELLO 协议版本不兼容

如果你有具体的 OpenSSL 命令和报错信息,可以直接贴出来,我可以帮你逐行分析。

0 踩