如何从 PEM 编码的证书中确定 SSL 证书的到期日期?

如何从 PEM 编码的证书中确定 SSL 证书的到期日期?

问题描述:

如果我在 Mac 或 Linux 中有实际文件和 Bash shell,我如何查询证书文件的到期时间?不是网站,而是证书文件本身,假设我有 csr、密钥、pem 和链文件.

If I have the actual file and a Bash shell in Mac or Linux, how can I query the cert file for when it will expire? Not a web site, but actually the certificate file itself, assuming I have the csr, key, pem and chain files.

With openssl:

openssl x509 -enddate -noout -in file.pem

输出在表单上:

notAfter=Nov  3 22:23:50 2014 GMT

另请参阅MikeW 的回答,了解如何轻松检查证书是否已过期,或者是否会在特定时间段,无需解析上面的日期.

Also see MikeW's answer for how to easily check whether the certificate has expired or not, or whether it will within a certain time period, without having to parse the date above.