OpenSSL Basics: Create, Inspect and Verify Certificates Like a Pro


Every padlock icon in your browser depends on certificates, and OpenSSL is the free tool that creates, reads and checks them. It is already installed on almost every Linux system and Mac, and it is one of those tools that looks intimidating until someone shows you the five commands that matter. Here they are.

What OpenSSL Actually Does

OpenSSL is a toolkit for cryptography. It implements TLS (the protocol behind HTTPS), creates private keys and certificates, and lets you inspect the cryptographic details of any connection. Server admins use it daily; security testers use it to verify that a site's encryption is actually configured correctly. You do not need to understand the math — you need to know the commands.

Create a Private Key and Certificate

For your own lab or a local test server, a self-signed certificate takes two commands:

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key
openssl req -new -x509 -key server.key -out server.crt -days 365 \
  -subj "/CN=lab.local"

The first command creates a 2048-bit RSA private key. The second creates a certificate valid for 365 days. Never use a self-signed certificate on a public site — browsers will warn users, and rightly so. For anything public, use a free certificate from Let's Encrypt instead.

Inspect Any Website's Certificate

This is the most useful OpenSSL trick for security work. Connect to any site and dump its certificate chain:

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

The output shows who issued the certificate, which domain it covers, and — most importantly — when it expires. Add -showcerts to see the full chain, and check whether the chain is complete: a missing intermediate certificate is one of the most common reasons a site breaks in some browsers but not others.

Check Expiry Before It Breaks Things

Expired certificates take sites offline, and they do it silently at 3 a.m. Check a local certificate file like this:

openssl x509 -in server.crt -noout -enddate
openssl x509 -in server.crt -noout -text | grep -A2 "Subject Alternative"

The second command shows the Subject Alternative Names — the list of domains the certificate actually covers. A certificate that does not list your domain will trigger a browser warning even if everything else is perfect.

Verify a Certificate Chain

To confirm a certificate is genuinely trusted by your system, verify it against the CA bundle:

openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt server.crt

If it prints OK, the chain is valid. If it fails, the certificate is expired, self-signed, or chained to a root your system does not trust — each failure tells you exactly what to fix.

Three Rules to Remember

  • Protect the private key. A .key file is the crown jewel — anyone holding it can impersonate your server. Keep it at chmod 600 and never commit it to git.
  • Use 2048-bit RSA or ECDSA. Anything smaller is weak; anything bigger is usually unnecessary overhead.
  • Automate expiry checks. Certificates expire, and humans forget. A weekly cron job that runs the expiry check and emails you when a certificate has under 30 days left will save you from a very bad morning.

OpenSSL looks like a cryptographer's tool, but for defenders it is a flashlight: point it at any certificate and it tells you the truth. Learn these five commands and you will never be surprised by an expired certificate again.

Comments

Popular Posts