A browser that trusts a site and a command-line client that rejects it are usually looking at the same certificate but a different chain. To verify a TLS certificate chain with OpenSSL you do three things: pull the certificates the server actually presents with openssl s_client -connect host:443 -showcerts, check that they link into a trusted root with openssl verify -CAfile, and read the individual certificates with openssl x509 -noout -text to confirm dates, issuer, and subject. The single most common failure, “unable to get local issuer certificate”, almost always means the server forgot to send an intermediate, not that the certificate is bad. This guide walks the whole path.
What you’ll accomplish
- Capture the exact certificate chain a server presents over TLS, in the order it sends them.
- Confirm the chain links leaf to intermediate to a trusted root, with a clean
Verify return code: 0 (ok). - Inspect any single certificate for its subject, issuer, validity dates, and SAN entries.
- Diagnose the classic “unable to get local issuer certificate” error and tell a server misconfiguration apart from a trust-store gap.
- Know when OpenSSL is the wrong tool and a browser or monitoring check fits better.
Prerequisites
- OpenSSL installed. Check the build with
openssl version. This matters more than it looks: many macOS machines symlinkopensslto LibreSSL, whoses_clientoutput and flag support differ from the OpenSSL project’s tool. - Shell access on a machine that can reach the target host on port 443 (or whatever TLS port you are testing). A firewall between you and the host will look like a chain problem when it is not.
- A hostname to test. The examples use
example.com; substitute your own.
Run the version check first:
openssl version
OpenSSL 3.0.13 30 Jan 2024
If you instead see LibreSSL 3.3.6, install the OpenSSL project build (on macOS, brew install openssl@3 gives you /opt/homebrew/opt/openssl@3/bin/openssl) and use that binary for the commands below. LibreSSL works for basic connects but its -verify and -showcerts behavior is not identical, and chasing a chain bug is not the moment for a subtly different tool.
How it works
A server does not send you a single certificate. It sends a chain: the leaf certificate for its hostname, then the intermediate CA certificate that signed the leaf, and sometimes more intermediates above that. Each certificate is signed by the private key of the one above it. At the top sits a root CA, which is self-signed and lives in your operating system’s trust store, not on the wire. Verification means walking from the leaf upward, matching each certificate’s issuer to the subject of the next one, until you reach a root you already trust.
Order matters on the wire. TLS expects the leaf first, then each issuer above it. A server that sends the leaf but omits the intermediate leaves the client with a gap it cannot bridge on its own, because the intermediate is not in anyone’s trust store, only the root is. Browsers often paper over this by caching intermediates or fetching them through the certificate’s AIA (Authority Information Access) extension, which is exactly why a site can work in Chrome and fail under curl or an OpenSSL check. What verify actually checks is threefold: that each signature in the chain is valid, that every certificate is inside its validity window (not expired, not future-dated), and that the chain terminates at a trusted root.
Step-by-step
1. Pull the live chain with s_client. The -showcerts flag prints every certificate the server sends, PEM-encoded. The -servername flag sets the SNI hostname so a server hosting many sites on one IP returns the right certificate. Redirect stdin from /dev/null so the command returns instead of waiting for you to type an HTTP request:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
Near the top of the output, OpenSSL summarizes the chain it saw and its verdict:
Certificate chain
0 s:CN=example.com
i:C=US, O=DigiCert Inc, CN=DigiCert Global G3 TLS ECC SHA384 2020 CA1
-----BEGIN CERTIFICATE-----
MIIE...
-----END CERTIFICATE-----
1 s:C=US, O=DigiCert Inc, CN=DigiCert Global G3 TLS ECC SHA384 2020 CA1
i:C=US, O=DigiCert Inc, CN=DigiCert Global Root G3
-----BEGIN CERTIFICATE-----
MIIC...
-----END CERTIFICATE-----
Read the s: (subject) and i: (issuer) lines like a ladder: entry 0 is the leaf, its issuer is the subject of entry 1, and so on. If the last entry’s issuer is not also its subject, the root is being validated from your local store rather than sent, which is normal and correct.
2. Read the verdict s_client already computed. Further down, s_client prints its own verification result. This is the fastest possible check:
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | grep -E "Verify return code|verify"
Verify return code: 0 (ok)
0 (ok) means the chain validated against your system trust store. Any non-zero code is the thread to pull, and the number tells you which check failed.
3. Save the chain to files so you can verify it explicitly. The -showcerts block above contains every PEM in order. Split them: put the leaf in leaf.pem and the intermediate(s) in chain.pem. You can extract them by hand from the output, or capture the whole block:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null > allcerts.pem
Each -----BEGIN CERTIFICATE-----…-----END CERTIFICATE----- block in allcerts.pem is one certificate. The first is the leaf; the rest are intermediates.
4. Verify the leaf against the intermediates and system roots. openssl verify takes the untrusted intermediates with -untrusted and validates up to the roots your system already trusts:
openssl verify -untrusted allcerts.pem leaf.pem
leaf.pem: OK
OK means OpenSSL built a full path from the leaf, through the intermediates you supplied, to a trusted root. To validate against a specific root bundle instead of the system store, for example when testing an internal CA, point -CAfile at that bundle:
openssl verify -CAfile /path/to/ca-bundle.pem -untrusted intermediates.pem leaf.pem
leaf.pem: OK
5. Inspect a single certificate. Once you have a PEM, openssl x509 decodes it. The most useful three views: full text, just the dates, and just the names.
openssl x509 -in leaf.pem -noout -dates -issuer -subject
notBefore=Jun 1 00:00:00 2026 GMT
notAfter=Aug 30 23:59:59 2026 GMT
issuer=C=US, O=DigiCert Inc, CN=DigiCert Global G3 TLS ECC SHA384 2020 CA1
subject=CN=example.com
For the whole certificate including the Subject Alternative Names, which is what a browser actually matches the hostname against, ask for the text and filter:
openssl x509 -in leaf.pem -noout -text | grep -A1 "Subject Alternative Name"
X509v3 Subject Alternative Name:
DNS:example.com, DNS:www.example.com
6. Confirm the leaf and its issuer actually link. A subject line on the leaf and an issuer line that names the intermediate is not proof; the signature has to match. Compare the leaf’s issuer hash to the intermediate’s subject hash:
openssl x509 -in leaf.pem -noout -issuer_hash
openssl x509 -in intermediate.pem -noout -subject_hash
a1b2c3d4
a1b2c3d4
Matching hashes confirm the leaf was issued by that exact intermediate, not merely one with a similar name.
Validate it works
Run the end-to-end check and confirm all three signals line up:
openssl s_client ... </dev/nullprintsVerify return code: 0 (ok).openssl verify -untrusted allcerts.pem leaf.pemprintsleaf.pem: OK.openssl x509 -in leaf.pem -noout -datesshows anotAfterdate that is in the future, andnotBeforein the past.
A quick way to confirm the chain the server sends is complete on its own (independent of your local trust store papering over a gap) is to count the certificates it returned:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | grep -c "BEGIN CERTIFICATE"
2
For a publicly trusted certificate you almost always expect at least two: the leaf plus one intermediate. A count of exactly 1 is the tell-tale sign of a server that is not sending its intermediate, which brings us to the errors.
Troubleshooting
unable to get local issuer certificate. The most common one. OpenSSL walked up the chain and could not find the issuer of the last certificate it has. Ninety percent of the time the server is not sending the intermediate: thegrep -c "BEGIN CERTIFICATE"count comes back1. Fix it on the server by concatenating the intermediate to the leaf in the certificate file it serves (the “fullchain” file that tools like Certbot produce already does this). The other ten percent: the certificate is fine but the root is not in your trust store, common on minimal containers missing theca-certificatespackage or when validating an internal CA. Installca-certificates, or pass the right root with-CAfile.self signed certificate in certificate chain. OpenSSL reached a self-signed certificate that is not in your trust store. Either the server is presenting a private/internal CA that your machine does not trust (expected inside a corporate network; add the CA with-CAfile), or something upstream is intercepting TLS and substituting its own root, which is worth knowing about.certificate has expiredorcertificate is not yet valid. A certificate in the chain is outside its validity window. Do not assume it is the leaf. Intermediates expire too, and an expired intermediate breaks every leaf under it while the leaf’s own dates look perfect. Check each certificate’s dates:openssl x509 -in intermediate.pem -noout -dates. Compare against the machine clock, because a wrong local clock produces this error against a perfectly valid certificate.- Wrong chain order. Some servers send certificates in the wrong order (intermediate before leaf, or leaf plus a stray unrelated certificate). Strict clients reject this even when all the right certificates are present. In the
s_clientoutput the0entry must be the leaf whose subject is your hostname. If entry0is a CA, the order is wrong; fix the certificate file on the server so the leaf comes first. - A different certificate comes back than expected (SNI). On shared IPs, omitting
-servernamemakes the server return its default certificate, not yours, so you diagnose the wrong host. Always pass-servername <hostname>matching the-connecthost. If adding-servernamesuddenly returns the right certificate, the server relies on SNI and any client that does not send it will get the default.
When this is the wrong approach
OpenSSL tells you what a server presents and whether that links to a root your machine trusts, from one machine at one moment. It does not tell you what a specific browser will do: browsers keep their own trust stores, cache intermediates, fetch missing ones via AIA, and enforce policies (CT logs, name constraints, distrust dates) that OpenSSL does not check by default. A chain that OpenSSL calls OK can still fail in an old Android release with a stale root, and one OpenSSL flags can work in Chrome because Chrome fetched the missing intermediate. For catching expiry before it bites, a scheduled monitoring probe beats a manual check, and for latency in the handshake itself see diagnosing TLS handshake latency on a cloud VM. To attribute where the TLS phase sits in overall request time, break request latency into phases with curl. The authoritative reference for every flag used here is the OpenSSL documentation, specifically the s_client and verify manual pages.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.