$ openssl s_client -servername {SERVER_NAME} -connect {SERVER_NAME}:{PORT} | openssl x509 -noout -dates

了解openssl命令选项

openssl是一个非常有用的TLS和SSL服务器的诊断工具。openssl命令行选项如下。

s_client : s_client命令实现了一个通用的SSL/TLS客户端,它使用SSL/TLS连接到远程主机。

-servername $DOM : 将 ClientHello 消息中的 TLS SNI (Server Name Indication) 扩展名设置为给定值。

-connect $DOM:$PORT : 指定要连接的主机 ($DOM) 和可选的端口 ($PORT) 。

x509 : 运行证书显示和签名工具。

-noout : 防止输出证书的编码版本。

-dates : 打印证书的开始和到期时间。打印 TLS 或 SSL 证书的开始和到期日期。

openssl s_client -servername www.baidu.com -connect www.baidu.com:443 |openssl x509 -noout -datesdepth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CAverify return:1depth=1 C = BE, O = GlobalSign nv-sa, CN = GlobalSign Organization Validation CA - SHA256 - G2verify return:1depth=0 C = CN, ST = beijing, L = beijing, OU = service operation department, O = "Beijing Baidu Netcom Science Technology Co., Ltd", CN = baidu.comverify return:1notBefore=Apr  2 07:04:58 2020 GMTnotAfter=Jul 26 05:31:02 2021 GMT

结果对比截图

多说一句有的配置文件中你看到的可能是PEM文件,其实PEM就是这样来的

cat 1_www.abc.com_bundle.crt 2_www.abc.com.key > www.abc.com.pem

下面罗列我申请的一个ssl证书的大概文件,我将我的域名替换了。

.

├── Apache

│ ├── 1_root_bundle.crt

│ ├── 2_www.snsyr.com.crt

│ └── 3_www.snsyr.com.key

├── IIS

│ ├── keystorePass.txt

│ └── www.snsyr.com.pfx

├── Nginx

│ ├── 1_www.snsyr.com_bundle.crt

│ ├── 2_www.snsyr.com.key

├── Tomcat

│ ├── keystorePass.txt

│ └── www.snsyr.com.jks

└── www.snsyr.com.csr

从PEM编码的证书文件中查找SSL证书的到期日

语法如下 查询证书文件中TLS/SSL证书的过期时间。

$ openssl x509 -enddate -noout -in {/path/to/my/my.pem}$ openssl x509 -enddate -noout -in /etc/nginx/ssl/www.abci.biz.fullchain.cer.ecc$ openssl x509 -enddate -noout -in /etc/nginx/ssl/www.nixcraft.com.fullchain.cer

➜ Nginx openssl x509 -enddate -noout -in 1_www.abc.com_bundle.crt

notAfter=Oct 22 23:59:59 2021 GMT

➜ Nginx openssl x509 -enddate -noout -in www.abc.com.pem

notAfter=Oct 22 23:59:59 2021 GMT

我们也可以检查证书是否在给定的时间范围内过期。例如,查找TLS/SSL证书是否在未来7天(604800秒)内过期。

$ openssl x509 -enddate -noout -in my.pem -checkend 604800# Check if the TLS/SSL cert will expire in next 4 months #openssl x509 -enddate -noout -in my.pem -checkend 10520000

如果自己要写脚本的话,自由发挥下就可以了

DOM="www.baidu.com"PORT="443"## note echo added ##echo | openssl s_client -servername $DOM -connect $DOM:$PORT | openssl x509 -noout -dates

可以参考

https://testssl.sh

另一个比较好的就是ngios的check_http

http://nagios-plugins.org/doc/man/check_http.html

# /usr/lib64/nagios/plugins/check_http -H www.abc.cn -C 30,14

SSL OK - Certificate 'www.abc.cn' will expire on 2019-07-10 20:00 +0800/CST. HTTP OK: HTTP/1.1 200 OK - 4756 bytes in 3.038 second response time |time=3.037933s;;;0.000000 size=4756B;;;0

-C, --certificate=INTEGER[,INTEGER]    Minimum number of days a certificate has to be valid. Port defaults to 443    (when this option is used the URL is not checked.)Examples: CHECK CONTENT: check_http -w 5 -c 10 --ssl -H www.verisign.com When the 'www.verisign.com' server returns its content within 5 seconds, a STATE_OK will be returned. When the server returns its content but exceeds the 5-second threshold, a STATE_WARNING will be returned. When an error occurs, a STATE_CRITICAL will be returned. CHECK CERTIFICATE: check_http -H www.verisign.com -C 14 When the certificate of 'www.verisign.com' is valid for more than 14 days, a STATE_OK is returned. When the certificate is still valid, but for less than 14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when the certificate is expired. CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14 When the certificate of 'www.verisign.com' is valid for more than 30 days, a STATE_OK is returned. When the certificate is still valid, but for less than 30 days, but more than 14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when certificate expires in less than 14 days CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com all these options are needed: -I  -p  -u  -S(sl) -j CONNECT -H  a STATE_OK will be returned. When the server returns its content but exceeds the 5-second threshold, a STATE_WARNING will be returned. When an error occurs, a STATE_CRITICAL will be returned.

x509证书_从Linux shell提示符中查看TLS/SSL证书有效期相关推荐

  1. linux服务器证书安装教程,linux服务器使用certbot免费安装ssl证书

    这里介绍一个免费的生成https的网站: certbot的官方网站为:https://certbot.eff.org 打开这个链接选择自己使用的 web server 和操作系统,如下图: 选好系统后 ...

  2. Linux - C SHELL提示符中显示时间,设置在切换小时时不提示“DING!“

    C SHELL提示符中显示时间,设置在切换小时时不提示"DING!" 问题 终端提示符中显示时间,如何设置在切换小时时不提示"DING!"? 解决 查看tcsh ...

  3. linux shell脚本字符串连接符,学习Linux shell脚本中连接字符串的方法

    这篇文章主要介绍了Linux shell脚本中连接字符串的方法,如果想要在变量后面添加一个字符,可以用一下方法: 代码如下: $value1=home $value2=${value1}"= ...

  4. Linux Shell脚本中压缩包解压到目标目录下

    在Linux Shell脚本中,把一个压缩文件解压到目标目录下,使用如下代码: tar -xvf server.tar -C /opt/ 上述命令实现了把当前目录下的server.tar的压缩包,解压 ...

  5. 在 Linux shell 字符串中,百分比符号是什么?

    当你正在学习如何完全使用 Linux shell 时,你可以能会觉得自己能够对字符串进行操作. 记住,今天q&一个文章的超级用户对读者的一个奇怪问题有答案. 今天,回答会话的问题来自超级用户的 ...

  6. Linux Shell - 脚本中自动确认需要输入确认的命令

    文章目录 Linux Shell - 脚本中自动确认需要输入确认的命令 1.yum 命令 2.其它命令 Linux Shell - 脚本中自动确认需要输入确认的命令 1.yum 命令 通过指定 -y ...

  7. linux脚本用户输入,如何在Linux shell脚本中提示用户输入

    本篇文章给大家介绍关于如何在Linux shell脚本中提示用户输入?下面来看具体的内容. 我们首先来看一下命令# read var # read -s "Waiting for input ...

  8. linux shell比大小expr,Linux shell命令中expr(示例代码)

    在Linux shell命令中expr虽然不是很起眼,但是它的作用是非常大的!到目前为止,我个人看来最大的作用就是两个--四则运算和字符串的操作. 先说四则运算,在Shell中四则运算不能简简单单的加 ...

  9. 查看依赖树_如何在基于 Ubuntu 或 Debian 的 Linux 发行版中查看一个软件包的依赖...

    但如果你想在安装一个软件包之前或之后知晓这个软件包的依赖,那该怎么办呢? 来源:https://linux.cn/article-12987-1.html 作者:Abhishek Prakash 译者 ...

最新文章

  1. 【NIO】异步模型之Callback -- 封装NIO
  2. 运用Smark.SocketAsyncs方便实现数据交互服务
  3. django 的 一对多的关系
  4. rnn按时间展开_双向RNN的理解
  5. FutureTask 示例
  6. java nutz_jnutz: 基于nutz的java+js混合开发项目
  7. 震撼!7月12日山东滨州,中科院向起电的雷暴云发射拖带金属导线专用火箭人工引雷!...
  8. python如何互换_python中怎么交换列的顺序
  9. jq 检测元素内html变化,jq 监听 textarea 元素内容变化的方法
  10. 零起点英语_【德国零起点】05—变元音字母
  11. NUC1100 Biorhythms【中国剩余定理】
  12. Oracle 拼接结果过长,ora-01489 字符串连接的结果过长 解决方案
  13. SMART Utility for mac (硬盘检测工具)
  14. java中的轻重量级组件_java Swing AWT 轻量级组建 和 重量级组件
  15. 修改树莓派默认密码及切换root账号
  16. nssl 1336.膜拜神牛 {LIS}
  17. 鼠标清除计算机密码,装机大师PE怎么清除修改电脑密码
  18. [Python从零到壹] 五十八.图像增强及运算篇之图像锐化Sobel、Laplacian算子实现边缘检测
  19. 微信小程序模仿拼多多APP地址选择样式
  20. 邓白氏编码申请最后提交资料格式

热门文章

  1. 直播类app开发的开屏广告是怎样实现的
  2. TrueType字体
  3. MIPS汇编语言开发环境MARS
  4. 山东的超级计算机,中支槽波动,山东21日将要开启降雨,超级计算机:开始雨比较弱...
  5. Android 前沿UI
  6. 金字塔—演绎与归纳推理的区别
  7. div清除浮动的四种方式
  8. 计算机基础知识:通用快速进入Windows用户某个文件夹
  9. 2019全国计算机二级照片要求,各省2019年9月全国计算机等级考试对报名的照片都有哪些要求?...
  10. AHT20温湿度传感器的数据采集