Skip to content
Log In Sign Up info@muvcloud.com

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 and i: 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

CodeMeaning
0Verified
10Certificate has expired
18Self-signed certificate
19Self-signed root in the chain
20Local issuer not found
21First 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

OptionUse
-alpn h2Asks for HTTP/2
-CAfile ca.crtTrusts your own CA
-cert, -keyClient certificate
-4, -6IPv4 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.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations