Security & TLSUpdated: 2026-11-06

Essential OpenSSL Key Generation, CSR, TLS & Certificate Commands

Quick reference for creating private keys, generating Certificate Signing Requests (CSR), verifying X.509 expiration dates, and converting certificate formats.

OpenSSL is the cryptographic workhorse powering TLS encryption across the internet. From generating 4096-bit RSA keys and modern elliptic curves (secp384r1) to inspecting remote server SSL certificate expiration dates without a browser, this cheat sheet covers core commands.

Key & CSR Generation Commands

Generating private keys and Certificate Signing Requests.

OperationCommand SyntaxDescription
Generate RSA Private Key`openssl genrsa -out private.key 4096`Creates high-security 4096-bit RSA private key.
Generate ECDSA Key`openssl ecparam -name secp384r1 -genkey -out ec.key`Generates modern elliptic curve key (faster and smaller than RSA).
Create CSR Request`openssl req -new -key private.key -out domain.csr`Generates certificate signing request for CA submission.
Self-Signed Certificate`openssl req -x509 -newkey rsa:4096 -keyout k.pem -out c.pem -days 365 -nodes`Creates 1-year self-signed TLS certificate for local dev.

Inspecting Certificates & Expiration

Validating certificate properties and testing live TLS handshakes.

Audit TaskCommand SyntaxOutput Information
Check Expiration Date`openssl x509 -in cert.crt -noout -enddate`Displays exact UTC expiration timestamp.
Inspect Full Details`openssl x509 -in cert.crt -noout -text`Prints Subject Alternative Names (SAN), issuer, and serial number.
Test Live Remote Server`openssl s_client -connect example.com:443 -servername example.com`Performs live TLS handshake and prints entire certificate chain.

Frequently Asked Questions

What is the difference between PEM and DER format?

PEM is ASCII Base64 encoded text enclosed in "-----BEGIN CERTIFICATE-----" headers. DER is raw binary encoding. Use openssl x509 -in cert.pem -outform der -out cert.der to convert.

Why should modern projects use ECDSA over RSA?

ECDSA provides equivalent cryptographic strength with much smaller key lengths (256-bit ECDSA equals 3072-bit RSA), speeding up TLS handshakes on mobile devices.