OpenSSL is the Swiss-army knife for TLS and cryptography on the command line: generating keys, creating certificate signing requests, inspecting and converting certificates, computing digests, encrypting files and probing live TLS servers. This cheatsheet collects the subcommands you reach for most, each with a runnable example.
How it works
The CLI is structured as openssl <subcommand> [options]. Each subcommand is a
small tool: genpkey/genrsa create keys, req builds CSRs and self-signed
certs, x509 reads and transforms certificates, s_client connects to a TLS
endpoint, dgst hashes and signs, enc does symmetric encryption, and pkcs12
bundles keys and certs. Options control input/output files, algorithms and
formats (PEM vs DER).
Common recipes
# Key + self-signed cert in one step (10 years)
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem \
-days 3650 -nodes -subj "/CN=example.com"
# Show certificate details and SAN
openssl x509 -in cert.pem -noout -text
# Test a live TLS endpoint
openssl s_client -connect example.com:443 -servername example.com
Notes and tips
-nodes (no DES) leaves the private key unencrypted — convenient for servers but
keep the file permissions tight. Use -subj "/CN=…" to fill CSR fields
non-interactively in scripts. PEM is the Base64 -----BEGIN----- format; add
-inform DER/-outform DER to work with binary. When testing TLS, always pass
-servername so SNI selects the right certificate on shared hosting.