如何将证书文件与密钥文件匹配?

Mal*_*hio 8 ubuntu ssl ssl-certificate apache-2.2

我有一个前系统管理员颁发的 SSL 证书(crt 文件)。搜索文件系统我发现了几个 .key 文件。如何将 crt 与密钥文件匹配并确认它们匹配?这是带有 Apache2 modssl 的 Ubuntu Server 11.10。

Sha*_*den 17

比较文件的模数。

像这样检查公钥:

openssl x509 -in /path/to/cert.crt -noout -text
Run Code Online (Sandbox Code Playgroud)

并像这样检查私钥:

openssl rsa -in /path/to/cert.key -noout -text
Run Code Online (Sandbox Code Playgroud)

比较证书和可能匹配的密钥之间的“模数”数据(一大块数字)。如果它们匹配,则密钥和证书是一对。

  • +1; 您也可以使用 `-modulus` 而不是 `-text` - 它将只输出模数(相同的结果,但使用 `uniq` 等可能更容易编写脚本)。 (6认同)
  • 并使用哈希使比较容易在眼球上进行:`openssl x509 -in /path/to/cert.crt -noout -modulus | openssl md5` 和 `openssl rsa -in /path/to/cert.key -noout -modulus | openssl md5` (2认同)