openssl s_client

ネットワーク

書き方

openssl s_client -connect <host>:443 -servername <host>

TLS 接続を素で開き、証明書と握手の過程をのぞきます。`-servername` を省くと一つの住所に多くの site を置くサーバーが既定の証明書を返して「別物」が見え、`< /dev/null` を付けないと入力を待って止まったままになります。

よく使うオプション

オプション意味
-connect host:443Where to open the TLS connection.
-servername <host>The SNI name. Without it a shared host serves its default certificate.
-showcertsPrint the whole chain the server sent, not just the leaf.
-tls1_2 / -tls1_3Force one protocol version, to test what the server still accepts.
-verify_return_errorFail instead of continuing when the chain does not validate.
< /dev/nullClose 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 -dates

When the certificate expires.

openssl s_client -connect example.com:443 -showcerts < /dev/null

Inspect the full chain for a missing intermediate.

つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. openssl s_client は何をしますか。

TLS 接続を素で開き、証明書と握手の過程をのぞきます。`-servername` を省くと一つの住所に多くの site を置くサーバーが既定の証明書を返して「別物」が見え、`< /dev/null` を付けないと入力を待って止まったままになります。

Q. どう打ちますか。

openssl s_client -connect <host>:443 -servername <host> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man openssl にあります。このコマンドはネットワークの仲間です。

関連するコマンド

man ページ: man openssl-s_client