Inspecting certificates & CSRsGenerating keys, CSRs & self-signed certsConverting between formatsVerifying keys & chains matchTesting a live server

Inspecting certificates & CSRs

CommandWhat it does
openssl x509 -in cert.pem -text -nooutView every field in a PEM certificate — subject, issuer, validity, SAN, everything.
openssl x509 -in cert.pem -noout -datesShow just the validity window (Not Before / Not After).
openssl x509 -in cert.pem -noout -subject -issuerShow just the Subject and Issuer, one line each.
openssl x509 -in cert.pem -noout -fingerprint -sha256Get the certificate's SHA-256 fingerprint.
openssl req -in request.csr -text -noout -verifyDecode a CSR and confirm its signature is internally valid.
openssl s_client -connect host:443 -showcertsConnect to a live server and show the full chain it presents.

Generating keys, CSRs & self-signed certs

CommandWhat it does
openssl genrsa -out key.pem 2048Generate a 2048-bit RSA private key (PKCS#1 format).
openssl ecparam -genkey -name prime256v1 -out key.pemGenerate an ECDSA private key on the P-256 curve.
openssl req -new -key key.pem -out request.csrGenerate a CSR from an existing private key, prompting for subject fields.
openssl req -new -newkey rsa:2048 -nodes -keyout key.pem -out request.csrGenerate a new key and CSR together, in one command.
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365Generate a self-signed certificate and key together — for local dev only.

Converting between formats

CommandWhat it does
openssl x509 -in cert.pem -outform der -out cert.derPEM certificate → DER.
openssl x509 -inform der -in cert.der -out cert.pemDER certificate → PEM.
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -certfile chain.pemCombine a PEM cert, key, and chain into a PFX/P12 bundle.
openssl pkcs12 -in cert.pfx -out cert.pem -nodesExtract a certificate + key from a PFX/P12 file into PEM.
openssl rsa -in key.pem -out key_pkcs8.pemPKCS#1 ("RSA PRIVATE KEY") → still PKCS#1, re-saved.
openssl pkcs8 -topk8 -nocrypt -in key.pem -out key_pkcs8.pemPKCS#1 → PKCS#8 ("PRIVATE KEY").

Verifying keys & chains match

CommandWhat it does
openssl x509 -noout -modulus -in cert.pem | openssl md5Get a certificate's modulus hash — compare against the key's.
openssl rsa -noout -modulus -in key.pem | openssl md5Get a private key's modulus hash — compare against the cert's.
openssl verify -CAfile chain.pem cert.pemVerify a certificate against a specific CA chain file.
openssl s_client -connect host:443 -cert cert.pem -key key.pemTest a connection presenting a specific client certificate (mTLS).

Testing a live server

CommandWhat it does
openssl s_client -connect host:443 -servername hostConnect with SNI explicitly set — needed when testing a multi-cert server by IP.
openssl s_client -connect host:443 -tls1_2Force a specific TLS version to confirm whether a server accepts it.
openssl s_client -connect host:443 -statusRequest and display the stapled OCSP response, if any.
openssl s_client -connect host:587 -starttls smtpTest STARTTLS on a mail server (swap smtp for imap or pop3 as needed).
echo | openssl s_client -connect host:443 2>/dev/null | openssl x509 -noout -enddateOne-liner: check a live server's certificate expiry date.

Certificate file format reference

The extension alone is a convention, not a guarantee — always check a file's actual content (head -c 30 file) if you're unsure whether something is really PEM text or binary DER underneath.

ExtensionWhat it usually is
.pemBase64-encoded text, wrapped in -----BEGIN/END----- lines. The most common format; can hold a certificate, key, CSR, or chain.
.crt / .cerUsually PEM-encoded (sometimes DER) — a certificate specifically. The extension alone doesn't guarantee the encoding; check the file's actual content if unsure.
.keyA private key, usually PEM-encoded. Treat with the same care as a password.
.csrA Certificate Signing Request — PEM-encoded text containing a public key and identifying details, submitted to a CA.
.derBinary (not text) encoding of a certificate or key. The underlying format PEM is just a base64 wrapper around.
.pfx / .p12A single binary file (PKCS#12) bundling a certificate, its private key, and often the chain — password-protected.
.p7b / .p7cPKCS#7 — a certificate chain bundle, notably without the private key. Common on Windows and Java systems.

Common TLS-secured ports

Worth knowing when a connection test on the wrong port produces a confusing failure that has nothing to do with the certificate itself.

PortWhat runs there
443HTTPS — standard web traffic
465SMTPS — implicit TLS for outgoing mail
587SMTP with STARTTLS — the modern standard for outgoing mail submission
993IMAPS — implicit TLS for reading mail
995POP3S — implicit TLS for reading mail (older protocol)
636LDAPS — implicit TLS for directory services
989 / 990FTPS — implicit TLS for file transfer (data / control channels)
8443A common alternate HTTPS port for admin panels and internal tools