← Cheatsheets
Linux

openssl

openssl commands for generating keys, inspecting certificates, converting formats and testing TLS.

Key Generation

openssl genrsa -out key.pem 4096
openssl ecparam -genkey -name prime256v1 -out key.pem
openssl genpkey -algorithm ed25519 -out key.pem
openssl rand -hex 32

CSR & Self-Signed Certs

openssl req -new -key key.pem -out cert.csr
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
openssl req -x509 -key key.pem -in cert.csr -out cert.pem -days 365

Inspecting Certificates

openssl x509 -in cert.pem -text -noout
openssl x509 -in cert.pem -subject -noout
openssl x509 -in cert.pem -issuer -noout
openssl x509 -in cert.pem -dates -noout
openssl x509 -in cert.pem -fingerprint -noout
openssl req -in cert.csr -text -noout

Testing & Verification

openssl s_client -connect host:443
openssl s_client -connect host:443 -servername host
openssl verify -CAfile ca.pem cert.pem
openssl s_client -connect host:443 2>/dev/null | openssl x509 -noout -dates

Format Conversion

openssl pkcs12 -export -in cert.pem -inkey key.pem -out bundle.p12
openssl pkcs12 -in bundle.p12 -out cert.pem -nodes
openssl x509 -in cert.pem -outform DER -out cert.der
openssl x509 -in cert.der -inform DER -out cert.pem

Encryption & Hashing

openssl dgst -sha256 file.txt
openssl enc -aes-256-cbc -in file.txt -out file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt
openssl passwd -6 mypassword