When a site throws a certificate error, or you just want to see what a server is actually presenting, openssl is the quickest way to look. It ships with most Linux distributions and macOS, so there is usually nothing to install. Here is the short version.

1. Fetch the certificate a server is presenting

echo | openssl s_client -connect securetron.net:443 -servername securetron.net 2>/dev/null | openssl x509 -noout -dates -issuer -subject -ext subjectAltName

The -servername flag matters. Without SNI, a server hosting several sites may hand you the wrong certificate, usually its default one. The output gives you the validity window, the issuer, the subject, and the Subject Alternative Name list.

2. Check the expiry date on its own

openssl x509 -in cert.pem -noout -dates

Or, if you want a yes or no answer for monitoring:

openssl x509 -in cert.pem -noout -checkend 604800

It exits 0 if the certificate is still valid 7 days from now (604800 seconds), and 1 if it expires sooner. That makes it easy to wire into a cron check or a monitoring script.

3. See the whole chain

openssl s_client -connect securetron.net:443 -servername securetron.net -showcerts

This prints every certificate the server sends, leaf first, then intermediates. Look at the “Verify return code” line at the end: 0 (ok) means the chain validated against your local trust store. Anything else, like 19 (self-signed certificate in chain) or 21 (unable to verify the first certificate), tells you where the chain breaks.

4. Read a certificate file in full

openssl x509 -in cert.pem -noout -text

This prints everything: signature algorithm, key size, extensions, key usage, and the full SAN list. Two things worth checking here:

  • Subject Alternative Name, not the Common Name. Modern browsers validate the hostname against the SAN list, and the CN is effectively ignored. If a certificate has no SAN matching the hostname, browsers reject it even if the CN matches.
  • Signature algorithm and key. sha256WithRSAEncryption with a 2048-bit key, or an ECDSA key, is what you expect to see. Anything signed with SHA-1 is long past acceptable.

5. A quick fingerprint check

openssl x509 -in cert.pem -noout -fingerprint -sha256

Useful when you need to compare the certificate you see against the one a CA says it issued, for example after a renewal or a revocation event.

A few habits that pay off: check the expiry of anything you operate at least weekly (public certificates are now capped at 200 days, so the window for forgetting is short), check the chain from outside your own network rather than only from the server itself, and keep an eye on the SAN list when a site adds a subdomain and the certificate suddenly stops covering it.

What do you check first when a certificate error shows up: expiry, the chain, or the name?