Skip to content

How to Check SSL Certificate Details with OpenSSL

DodaTech 2 min read

In this tutorial, you'll learn about How to Check SSL Certificate Details with OpenSSL. We cover key concepts, practical examples, and best practices.

The Problem

You need to verify an SSL certificate's expiry date, issuer, subject alternative names, or the full certificate chain. Without inspection tools, you cannot diagnose certificate errors or plan renewals.

Quick Fix

Step 1: Check certificate expiry dates

openssl x509 -in /etc/ssl/certs/example.com.pem -noout -dates

Expected:

notBefore=Apr 15 12:34:56 2024 GMT
notAfter=Jul 14 12:34:56 2024 GMT

Step 2: Check a remote server's certificate

openssl s_client -connect example.com:443 -servername example.com < /dev/null 2>/dev/null | openssl x509 -noout -dates

This connects to the remote server, grabs the certificate, and shows the validity dates.

Step 3: View full certificate details

openssl x509 -in /etc/ssl/certs/example.com.pem -noout -text | head -30

Expected:

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            04:...
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = US, O = Let's Encrypt, CN = R3
        Validity
            Not Before: Apr 15 12:34:56 2024 GMT
            Not After : Jul 14 12:34:56 2024 GMT
        Subject: CN = example.com
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)

Step 4: Check Subject Alternative Names (SANs)

openssl x509 -in /etc/ssl/certs/example.com.pem -noout -ext subjectAltName

Expected:

X509v3 Subject Alternative Name:
    DNS:example.com, DNS:www.example.com, DNS:api.example.com

Step 5: Check the certificate chain

openssl s_client -connect example.com:443 -servername example.com -showcerts < /dev/null 2>/dev/null

Each certificate in the chain is displayed between -----BEGIN CERTIFICATE----- markers. The server certificate is first, followed by intermediates.

Step 6: Verify a certificate against a CA bundle

openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt example.com.pem

Expected:

example.com.pem: OK

Step 7: Check the certificate serial number and fingerprint

openssl x509 -in /etc/ssl/certs/example.com.pem -noout -fingerprint -sha256

Expected:

SHA256 Fingerprint=AB:CD:EF:...

Step 8: Check if the certificate matches a private key

openssl x509 -in example.com.pem -noout -modulus | openssl md5
openssl rsa -in example.com.key -noout -modulus | openssl md5

If the two MD5 hashes match, the certificate and key belong together.

Alternative Solutions

Use certbot certificates for Let's Encrypt certificates, which shows expiry and paths in a summary format.

Common Errors

openssl: command not found: Install OpenSSL: sudo apt install openssl -y. It is a core utility and widely available.

Unable to load certificate: The file is not in PEM format. Convert from DER: openssl x509 -inform der -in cert.der -out cert.pem.

s_client connection timed out: The remote server is not reachable on port 443. Check DNS resolution and firewall rules before debugging the certificate.

Certificate chain is incomplete: If the server returns only the leaf certificate, the chain is not configured. Ensure the fullchain.pem (not cert.pem) is used in the web server config.

Prevention

  • Check certificate expiry monthly with a cron job or monitoring tool.
  • Verify SANs match all domains served by the certificate.
  • Validate the full chain after renewal — missing intermediates cause browser warnings.
  • Set up alerts when certificates are within 30 days of expiry.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro