OpenSSL certificate reference

OpenSSL certificate commands: inspect, check expiry, verify a chain, match a key

This is a lookup table, not a tutorial. Each row is a command you can paste, with the question it answers. The commands assume OpenSSL 1.1.1 or later; where a flag needs a newer release it is called out in the row.

Decision brief

Primary query
openssl check certificate expiration
Best for
Engineers who run PKI or own cryptographic change and need reviewable evidence rather than a spreadsheet.
Safety boundary
Evidence supports decisions; it is not proof of implementation safety or compliance.

Most certificate incidents are diagnosed with four facts: what the certificate says, when it expires, whether the chain the server presents is complete and correctly ordered, and whether the private key on disk matches the certificate being served. OpenSSL answers all four from the command line, which is why it stays useful long after a dashboard has told you something is wrong without telling you what.

Two distinctions cause most confusion. Reading a file and reading a live endpoint are different operations: openssl x509 parses a file, openssl s_client speaks TLS and returns what the server sent. And a certificate that a browser accepts may still be misconfigured, because browsers repair an incomplete or misordered chain using cached intermediates while non-browser clients such as curl, Java, and Go do not.

Expiry checking is the one command worth wiring into automation rather than running by hand. The -checkend flag returns a non-zero exit status when a certificate will expire within the given number of seconds, so it slots straight into a monitoring check without any date parsing. Reading the notAfter string and comparing dates in a shell script is where certificate monitors usually acquire their bugs.

Reference

Values you can look up and check against your own systems

Read a certificate

QuestionCommand
Show everything in a certificate fileopenssl x509 -in cert.pem -noout -text
Subject, issuer and validity onlyopenssl x509 -in cert.pem -noout -subject -issuer -dates
Subject alternative namesopenssl x509 -in cert.pem -noout -ext subjectAltName
Serial number and fingerprintopenssl x509 -in cert.pem -noout -serial -fingerprint -sha256
Read a DER certificate instead of PEMopenssl x509 -in cert.der -inform DER -noout -text
Read a certificate out of a PKCS#12 bundleopenssl pkcs12 -in bundle.pfx -nokeys -clcerts | openssl x509 -noout -text

Check expiry

The -checkend flag exits 1 if the certificate expires within the given number of seconds and 0 if it does not, which is what makes it usable in a monitoring check.

QuestionCommand
When does this file expire?openssl x509 -in cert.pem -noout -enddate
Will it expire within 30 days?openssl x509 -in cert.pem -noout -checkend 2592000
Has it already expired?openssl x509 -in cert.pem -noout -checkend 0
When does a live endpoint's certificate expire?openssl s_client -connect host:443 -servername host </dev/null 2>/dev/null | openssl x509 -noout -enddate
Expiry of every certificate in a directoryfor f in *.pem; do echo "$f $(openssl x509 -in "$f" -noout -enddate)"; done

Inspect a live endpoint

The -servername flag sends SNI. Without it a virtual-hosted server returns its default certificate, not the one you meant to test.

QuestionCommand
What certificate does this host serve?openssl s_client -connect host:443 -servername host </dev/null 2>/dev/null | openssl x509 -noout -text
Show the full chain the server sentopenssl s_client -connect host:443 -servername host -showcerts </dev/null
Which protocol and cipher were negotiated?openssl s_client -connect host:443 -servername host </dev/null 2>&1 | grep -E 'Protocol|Cipher'
Test a mail server with STARTTLSopenssl s_client -starttls smtp -connect host:587
Test a Postgres endpointopenssl s_client -starttls postgres -connect host:5432

Verify trust and chain order

A chain must run leaf, then intermediate, then optionally root. Browsers often repair a wrong order; curl, Java and Go clients do not.

QuestionCommand
Does this chain verify against the system store?openssl verify -untrusted chain.pem cert.pem
Verify against a specific CA bundleopenssl verify -CAfile ca-bundle.pem cert.pem
Which certificate issued this one?openssl x509 -in cert.pem -noout -issuer
Is the served chain complete?openssl s_client -connect host:443 -servername host -showcerts </dev/null 2>&1 | grep -c 'BEGIN CERTIFICATE'
Check a certificate against a CRLopenssl verify -crl_check -CAfile ca-bundle.pem -CRLfile crl.pem cert.pem

Keys and signing requests

The three modulus hashes must be identical. If the key hash differs from the certificate hash, the server is holding the wrong key.

QuestionCommand
Hash of the certificate modulusopenssl x509 -noout -modulus -in cert.pem | openssl sha256
Hash of the private key modulusopenssl rsa -noout -modulus -in key.pem | openssl sha256
Hash of the CSR modulusopenssl req -noout -modulus -in req.csr | openssl sha256
Read and self-verify a CSRopenssl req -in req.csr -noout -text -verify
New key and CSR in one stepopenssl req -new -newkey rsa:2048 -nodes -keyout key.pem -out req.csr
CSR with subject alternative namesopenssl req -new -key key.pem -out req.csr -addext "subjectAltName=DNS:a.example,DNS:b.example"
Self-signed certificate for a labopenssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 90
Bundle a key and certificate into PKCS#12openssl pkcs12 -export -inkey key.pem -in cert.pem -certfile chain.pem -out bundle.pfx

Post-quantum additions in OpenSSL 3.5 and later

These subcommands do not exist in OpenSSL 3.4 or earlier. Check with openssl version first.

QuestionCommand
Which TLS groups does this build offer?openssl list -tls-groups
Are ML-KEM hybrids available?openssl list -tls-groups | grep -i mlkem
Which signature algorithms are available?openssl list -signature-algorithms
Generate an ML-DSA-65 keyopenssl genpkey -algorithm ML-DSA-65 -out mldsa.key
Which group did this handshake use?openssl s_client -connect host:443 -tls1_3 </dev/null 2>&1 | grep -i 'Negotiated TLS1.3 group'

Capabilities

What the operating model needs to do

01

File and endpoint separated

The x509 subcommand parses what is on disk. The s_client subcommand reports what a server actually sends, including a chain that disagrees with the file you deployed.

02

Expiry as an exit code

The -checkend flag gives a threshold check with no date arithmetic, which is the difference between a monitor that works and one that silently rots.

03

Chain order visible

The -showcerts flag prints the chain in the order the server sent it, which is the only way to see the misordering that browsers hide.

04

Key and certificate matched

Comparing modulus hashes across key, certificate and CSR settles the most common deployment mistake in one line.

Workflow

A repeatable path to evidence

Use explicit scope, accountable decisions, and verification gates. Keep unknowns visible so progress is not manufactured by narrowing the denominator.

  1. 1

    Reproduce from outside

    Query the endpoint over the network before reading anything on the host. The served certificate and the file on disk are frequently different.

  2. 2

    Read the dates

    Check notBefore as well as notAfter. A certificate installed early is as broken as one installed late.

  3. 3

    Verify the chain

    Run openssl verify against an explicit CA bundle rather than trusting that a browser accepted it.

  4. 4

    Record it

    Put the endpoint, issuer, expiry, key algorithm and negotiated group into the inventory so the next expiry is not a surprise.

Expected deliverables

Artifacts the next team can inspect

  • Per-endpoint certificate record with issuer and expiry
  • Chain completeness and ordering result
  • Key-to-certificate match evidence
  • Automated -checkend threshold check
  • Negotiated protocol, cipher and group per endpoint

Buyer checklist

Questions for a proof of value

  1. 01Is expiry monitored on the served certificate or only on the file in the repository?
  2. 02Does the monitor check the whole chain, or only the leaf?
  3. 03How are internal and private-CA certificates covered?
  4. 04Where are certificates that no automation knows about, such as appliances and vendor endpoints?
  5. 05Is the key algorithm and negotiated group recorded alongside expiry?

Limits and cautions

What this page does not promise

  • Only run these commands against systems you are authorized to test. The s_client subcommand opens a real connection.
  • A certificate a browser accepts can still fail for curl, Java or Go clients when the chain is incomplete or misordered.
  • Command flags vary between OpenSSL 1.1.1, 3.x and LibreSSL. Confirm with openssl version before assuming a flag exists.
  • Never publish or paste private key material while diagnosing. The modulus hash is enough to prove a match.
Local-first discovery

Talk to us about one representative repository

Qubrisk is in development and there is no self-serve signup yet. Tell us what your estate looks like and we will show you the evidence, the CBOM output, and the limits, without a sales sequence.

Contact us