The Basic Command
openssl s_client -connect example.com:443 -servername example.com </dev/null
-connect takes the host and port. -servername sends the name in the SNI extension, which tells a server with several sites which certificate to present. Current OpenSSL releases send SNI from the -connect host on their own when it is a DNS name, but writing it out is clearer, and it is required when you connect by IP address:
openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null
The </dev/null at the end gives s_client an empty input, so it closes the connection after the handshake. Without it, s_client waits for you to type; press Ctrl+D to end it, or type Q on a line of its own.
Reading the Output
- Certificate chain: one numbered entry per certificate sent, with
s:for the subject andi:for the issuer. Entry 0 is your site's certificate. - Server certificate: the site's certificate in PEM form.
- Protocol and cipher: the TLS version and cipher suite that were agreed.
- Verify return code: near the end.
0 (ok)means the chain is complete and trusted by the system's store of authorities.
Add -brief for a short summary of the protocol, cipher, and verification result.
Common Verify Return Codes
| Code | Meaning |
|---|---|
| 0 | Verified |
| 10 | Certificate has expired |
| 18 | Self-signed certificate |
| 19 | Self-signed root in the chain |
| 20 | Local issuer not found |
| 21 | First certificate not verifiable |
Codes 20 and 21 on a site that works in some browsers usually mean the server sends its certificate without the intermediate. In Nginx, point ssl_certificate at the full chain file, for Let's Encrypt fullchain.pem, not cert.pem. s_client completes the handshake even when verification fails; add -verify_return_error to make it abort instead.
Show the Whole Chain
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
-showcerts prints every certificate the server sends, not only the first. To read the dates and names of the site's own certificate, pipe the output into openssl x509:
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
Test a Specific TLS Version
openssl s_client -connect example.com:443 -servername example.com -tls1_2 </dev/null
openssl s_client -connect example.com:443 -servername example.com -tls1_3 </dev/null
Each command offers only that version. A successful handshake shows the protocol and cipher; a server that refuses the version ends with a handshake failure or a protocol version alert. Test both on any public site: current browsers use TLS 1.2 and 1.3 only. This is the first test for ERR_SSL_VERSION_OR_CIPHER_MISMATCH and for ERR_SSL_PROTOCOL_ERROR. Which versions your client supports depends on its OpenSSL release; see how to check the OpenSSL version.
Test Mail Servers with STARTTLS
Mail protocols start in plain text and switch to TLS with a STARTTLS command. s_client can send it for you:
openssl s_client -connect mail.example.com:587 -starttls smtp -servername mail.example.com </dev/null
openssl s_client -connect mail.example.com:25 -starttls smtp </dev/null
Other values include imap, pop3, ftp, ldap, mysql, and postgres. Ports with TLS from the first byte, such as 465, 993, and 995, need no -starttls.
Other Useful Options
| Option | Use |
|---|---|
-alpn h2 | Asks for HTTP/2 |
-CAfile ca.crt | Trusts your own CA |
-cert, -key | Client certificate |
-4, -6 | IPv4 or IPv6 only |
Testing IPv4 and IPv6 separately finds servers where one address family presents an old certificate. If the connection does not open at all, check the port first, as in the nc command.