Skip to main content

OpenSSL Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for OpenSSL commands for keys, CSRs, certificates, format conversion, TLS testing, random data, and hashes

OpenSSL is a command-line toolkit for TLS certificates, keys, cryptographic formats, and live connection testing. This cheatsheet collects common OpenSSL commands for generating keys, creating CSRs, inspecting certificates, converting formats, and debugging TLS services.

Version and Help

Check the installed OpenSSL version and find command help.

CommandDescription
openssl versionShow OpenSSL version
openssl version -aShow build details and paths
openssl helpList available commands
openssl req -helpShow help for the req command
openssl x509 -helpShow help for certificate inspection

Private Keys

Generate RSA and elliptic-curve private keys.

CommandDescription
openssl genrsa -out private.key 2048Generate RSA private key
openssl genrsa -out private.key 4096Generate larger RSA key
openssl genrsa -aes256 -out private.key 2048Generate encrypted RSA key
openssl rsa -in encrypted.key -out plain.keyRemove key passphrase
openssl ecparam -name prime256v1 -genkey -noout -out ec.keyGenerate EC private key
chmod 600 private.keyRestrict private key permissions

Certificate Signing Requests

Create CSRs for certificate authorities.

CommandDescription
openssl req -new -newkey rsa:2048 -noenc -keyout domain.key -out domain.csrGenerate key and CSR
openssl req -new -key domain.key -out domain.csrCreate CSR from existing key
openssl req -new -newkey rsa:2048 -noenc -keyout domain.key -out domain.csr -subj "/CN=example.com"Non-interactive CSR
openssl req -new -key domain.key -out domain.csr -addext "subjectAltName=DNS:example.com,DNS:www.example.com"CSR with SAN names
openssl req -in domain.csr -noout -textInspect CSR contents
openssl req -in domain.csr -noout -subjectPrint CSR subject

Self-Signed Certificates

Create local and internal certificates.

CommandDescription
openssl req -x509 -newkey rsa:2048 -noenc -keyout selfsigned.key -out selfsigned.crt -days 365Generate self-signed certificate
openssl req -x509 -new -key domain.key -out domain.crt -days 365Self-sign with existing key
openssl req -x509 -newkey rsa:2048 -noenc -keyout localhost.key -out localhost.crt -days 365 -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"Localhost certificate with SAN
openssl x509 -in selfsigned.crt -noout -textInspect certificate
openssl x509 -in selfsigned.crt -noout -datesShow validity dates

Certificate Inspection

Read certificate fields without opening a browser.

CommandDescription
openssl x509 -in cert.crt -noout -textShow full certificate details
openssl x509 -in cert.crt -noout -subjectShow subject
openssl x509 -in cert.crt -noout -issuerShow issuer
openssl x509 -in cert.crt -noout -datesShow notBefore and notAfter
openssl x509 -in cert.crt -noout -serialShow serial number
openssl x509 -in cert.crt -noout -fingerprint -sha256Show SHA-256 fingerprint

Match Key, CSR, and Certificate

Confirm that files belong together before deployment.

CommandDescription
openssl rsa -in domain.key -noout -modulus | openssl md5Hash RSA key modulus
openssl x509 -in domain.crt -noout -modulus | openssl md5Hash certificate modulus
openssl req -in domain.csr -noout -modulus | openssl md5Hash CSR modulus
openssl pkey -in private.key -pubout -outform pemExtract public key from private key
openssl x509 -in domain.crt -pubkey -nooutExtract public key from certificate

Format Conversion

Convert certificates between common encodings and bundles.

CommandDescription
openssl x509 -in cert.pem -outform der -out cert.derConvert PEM certificate to DER
openssl x509 -in cert.der -inform der -out cert.pemConvert DER certificate to PEM
openssl pkcs12 -export -out bundle.pfx -inkey domain.key -in domain.crtCreate PKCS#12 bundle
openssl pkcs12 -in bundle.pfx -out bundle.pem -noencExtract PEM from PKCS#12
openssl rsa -in private.key -outform der -out private.derConvert RSA key to DER

TLS Connection Testing

Debug live TLS services with s_client.

CommandDescription
openssl s_client -connect example.com:443 -servername example.comTest HTTPS with SNI
openssl s_client -connect mail.example.com:993 -servername mail.example.comTest IMAPS TLS
openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.comTest SMTP STARTTLS
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -datesShow remote certificate dates
openssl s_client -connect example.com:443 -tls1_3Force TLS 1.3
openssl s_client -connect example.com:443 -showcertsShow certificate chain

Random Data and Hashes

Generate tokens and verify file digests.

CommandDescription
openssl rand -base64 32Generate base64 token
openssl rand -hex 32Generate hex token
openssl dgst -sha256 file.isoSHA-256 file hash
openssl dgst -sha512 file.isoSHA-512 file hash
openssl dgst -sha256 -binary file.iso | openssl base64Base64-encoded binary digest

Use these references for certificate workflows.

GuideDescription
OpenSSL Command GuideFull OpenSSL tutorial with examples
Create a Self-Signed SSL CertificateStep-by-step self-signed certificate guide
What is an SSL Certificate?SSL/TLS certificate concepts
dig CommandCheck DNS before certificate testing