openssl s_client
網路
用法
openssl s_client -connect <host>:443 -servername <host>開一條裸的 TLS 連線,用來查看憑證和交握過程;不寫 `-servername`,一個位址上放多個網站的伺服器就會給你預設憑證,而不加 `< /dev/null` 它會一直等著輸入不返回。
常用選項
| 選項 | 含義 |
|---|---|
| -connect host:443 | Where to open the TLS connection. |
| -servername <host> | The SNI name. Without it a shared host serves its default certificate. |
| -showcerts | Print the whole chain the server sent, not just the leaf. |
| -tls1_2 / -tls1_3 | Force one protocol version, to test what the server still accepts. |
| -verify_return_error | Fail instead of continuing when the chain does not validate. |
| < /dev/null | Close stdin, or the command sits and waits forever. |
範例
openssl s_client -connect example.com:443 -servername example.com < /dev/null 2>/dev/null | openssl x509 -noout -datesWhen the certificate expires.
openssl s_client -connect example.com:443 -showcerts < /dev/nullInspect the full chain for a missing intermediate.
連不上的時候,這些能把範圍縮小——是名稱解析不了、沒有路由,還是連接埠被擋。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. openssl s_client 是做什麼的?
開一條裸的 TLS 連線,用來查看憑證和交握過程;不寫 `-servername`,一個位址上放多個網站的伺服器就會給你預設憑證,而不加 `< /dev/null` 它會一直等著輸入不返回。
Q. 怎麼寫?
openssl s_client -connect <host>:443 -servername <host> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man openssl。這條命令屬於網路。
相關命令
man 手冊: man openssl-s_client