OpenSSL Cheat Sheet
Certificates, keys, CSRs, and the TLS handshake checks — stay paranoid with one of the essential crypto tools.
Security4 sections · 24 commands
⌘K
Keys & Certificates
8openssl genrsa -out key.pem 2048Generate an RSA private key
openssl genpkey -algorithm ed25519 -out key.pemModern Ed25519 key
openssl req -x509 -new -key key.pem -days 365 -out cert.pemSelf-signed cert
openssl req -new -key key.pem -out csr.pemGenerate a CSR
openssl x509 -in cert.pem -text -nooutInspect certificate fields
openssl x509 -in cert.pem -noout -datesValidity period
openssl x509 -in cert.pem -noout -subject -issuerSubject and issuer
openssl x509 -in fullchain.pem -noout -fingerprint -sha256Certificate fingerprint
Testing TLS Connections
6openssl s_client -connect host:443Dump the TLS handshake
openssl s_client -connect host:443 -servername HOSTSNI-aware connection
echo | openssl s_client -connect host:443 2>/dev/null | openssl x509 -noout -datesCert dates for a live host
echo | openssl s_client -connect host:443 -servername HOST 2>/dev/null | grep -A1 'Verify return'Verify chain result
openssl s_client -connect host:443 -tls1_2 2>/dev/null >/dev/null; echo $?Is TLS 1.2 supported
openssl s_client -showcerts -connect host:443 </dev/null 2>/dev/null | openssl x509 -text -noout | head -20Inspect the served certificate
Hashing & Encryption
6openssl dgst -sha256 -hmac SECRET FILEHMAC-SHA256 of a file
openssl enc -aes-256-cbc -salt -in file -out file.encEncrypt a file (will prompt)
openssl enc -d -aes-256-cbc -in file.enc -out fileDecrypt a file
openssl rand -base64 32Random token for secrets
openssl req -text -noout -in csr.pemRead a CSR
openssl dhparam -out dhparam.pem 2048DH params for legacy TLS
Formats & Conversion
4openssl pkcs12 -export -out bundle.pfx -inkey key.pem -in cert.pemTo PKCS#12
openssl pkcs12 -in bundle.pfx -nodes -out key+cert.pemFrom PKCS#12
openssl rsa -in key.enc -out key.pemStrip encryption from a key
openssl crl2pkcs7 -nocrl -certfile cacert.pem | openssl pkcs7 -print_certs -nooutList CA bundle certs