Use openssl x509 to read a certificate file and openssl s_client to read the certificate a live server sends. Add openssl verify to test the chain. Each command below was run on a test certificate, so the output you see is real.
Google's HTTPS Transparency Report for June 2025 tracks encrypted web traffic. So checking certificates from the command line is now routine.
How Do You Check a Certificate File with OpenSSL?
Run openssl x509 -in server.crt -text -noout. The command decodes a PEM certificate and prints the subject, issuer, validity dates, public key and extensions. The -noout flag stops it from printing the encoded certificate again, which keeps the output readable.
- Issuer and Subject: who signed the certificate and who it was issued to.
- Validity: the Not Before and Not After dates.
- Subject Public Key Info: the key type and size, 2048-bit RSA in our test.
- X509v3 extensions: items such as the Subject Alternative Name list of hostnames.
The full output is long, so most people then ask for single fields instead.
Which Command Prints Only the Fields You Need?
Replace -text with a field flag. Each flag prints one detail, so you can read a result at a glance or use it in a script. The table lists the flags we used, and each one was run on the test certificate.
| You want | Command flag | What it printed |
|---|---|---|
| Subject and issuer | -subject -issuer | CN = example.test, issued by Test Root CA |
| Start and end dates | -dates | notBefore and notAfter lines |
| Fingerprint | -fingerprint -sha256 | A SHA-256 fingerprint |
| Hostnames covered | -ext subjectAltName | DNS:example.test, DNS:www.example.test |
| Allowed uses | -purpose | SSL server: Yes |

The subject, issuer and dates of the test certificate.
Our list of the most common OpenSSL commands covers key and CSR tasks that sit outside this check.
How Do You Check When a Certificate Expires?
Use -dates to read the end date, or -checkend to test it. The -checkend flag takes a number of seconds and answers whether the certificate will still be valid then. Its exit code is 0 for valid and 1 for expired, which suits monitoring scripts.

A test certificate valid for 90 days passes a one-day check and fails a 92-day check.
For more ways to do this, see our guide to checking expiry with OpenSSL.
How Do You Check the Certificate on a Live Server?
Run openssl s_client -connect host:443 -servername host, then pipe the result into openssl x509. The -servername flag sends the hostname, so servers that host many sites return the right certificate. Add -showcerts to print the whole chain the server sends.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -datesOur shell cannot reach outside sites, so we tested this against a local server we started with openssl s_server. Qualys SSL Pulse scans 150,000 popular sites, so the command applies to real servers in the same way.
How Do You Verify the Certificate Chain?
Run openssl verify -CAfile ca.crt server.crt. It prints OK when the certificate chains to the CA you name. Without the CA file, the check then fails with error 20. OpenSSL cannot find the issuer certificate in its trust store, so it cannot finish the chain.

The same certificate fails without the CA file and passes with it.
The same check through s_client returned code 21 without the CA and code 0 with it. Error 62 means the certificate does not cover the hostname you asked for.
| Verify code | Meaning | Fix |
|---|---|---|
| 0 (ok) | Chain and hostname are fine | None |
| 20 | The issuer certificate is missing from your trust store | Add the CA file or the intermediate certificate |
| 21 | OpenSSL could not verify the first certificate | Provide the full chain |
| 62 | Hostname mismatch | Use a certificate that lists the hostname |
How Do You Test the Hostname and the Server Response?
Add -verify_hostname to the s_client command, and the final verify line shows whether the certificate covers that name. The check also confirms the server answers over TLS. On the test server, a wrong name returned code 62, while the matching name returned code 0.

Verify results from the local test server, with a right and a wrong hostname.
The same run used TLS 1.3 with the cipher TLS_AES_256_GCM_SHA384.
How Do You Check That a Certificate Matches Its Private Key?
Compare the modulus of both files. Print each with -modulus, hash it with md5, and compare the two values. If they match, the key belongs to the certificate. In our test, both commands printed the same hash, so the pair matched.
openssl x509 -noout -modulus -in server.crt | openssl md5
openssl rsa -noout -modulus -in server.key | openssl md5This works for RSA keys. For help finding the key, see how to find your certificate private key.
What If the Certificate Is Not a PEM File?
OpenSSL assumes PEM text by default. A DER file needs -inform der, and a PFX file needs a pass phrase through openssl pkcs12. Our guide to SSL file extensions shows how to tell the formats apart, using the first line of each file.
Frequently Asked Questions
What is the OpenSSL command to check a certificate from a URL?
Run echo | openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -text. It fetches the live certificate and decodes it.
How do I decode a certificate with OpenSSL?
Use openssl x509 -in certificate.crt -text -noout for a PEM file. For a DER file, add -inform der.
What is the difference between openssl verify and openssl x509?
openssl x509 reads the contents of one certificate. openssl verify tests whether the certificate chains to a trusted CA.
What does the -checkend exit code mean?
Exit code 0 means the certificate will still be valid after the number of seconds you gave. Exit code 1 means it will have expired by then.
Can I check a certificate without the private key?
Yes. Reading and verifying a certificate needs only the certificate and, for verification, the CA file. The private key is needed only for the key-match check.
