====== 使用 curl 來查看 SSL 憑證資訊 ======
目前大多網站都已經改用 https , 如果在 linux 命令列模式想快速查看網站 SSL 憑證資訊, 可以透過 curl 來查詢.
===== 查詢方式 =====
* curl -v -k [網址] 2>&1 | grep -E "Connected to|subject|expire"
* Exp1. https://www.ichiayi.com
curl -v -k https://www.ichiayi.com 2>&1 | grep -E "Connected to|subject|expire"
* Connected to www.ichiayi.com (104.21.26.61) port 443 (#0)
* subject: C=US; ST=California; L=San Francisco; O=Cloudflare, Inc.; CN=sni.cloudflaressl.com
* expire date: Jun 10 23:59:59 2022 GMT
< set-cookie: DW7fa065a06cb74b536c124cfbe56ac6d3=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
< expires: Thu, 19 Nov 1981 08:52:00 GMT
* Exp2. https://demo.iiidevops.org
curl -v -k https://demo.iiidevops.org 2>&1 | grep -E "Connected to|subject|expire"
* Connected to demo.iiidevops.org (61.66.218.28) port 443 (#0)
* subject: CN=demo.iiidevops.org
* expire date: Nov 26 19:23:09 2021 GMT
* SSL certificate verify result: certificate has expired (10), continuing anyway.
* Exp3. https://demo.iiidevops.org (與 Exp2. 不同主機上執行)
curl -v -k https://demo.iiidevops.org 2>&1 | grep -E "Connected to|subject|expire"
* Connected to demo.iiidevops.org (61.66.218.25) port 443 (#0)
* subject: CN=demo.iiidevops.org
* expire date: Nov 26 19:23:09 2021 GMT
===== 參考網址 =====
* https://serverfault.com/questions/661978/displaying-a-remote-ssl-certificate-details-using-cli-tools
* https://stackoverflow.com/questions/42635253/display-received-cert-with-curl
{{tag>curl ssl cert}}