OpenSSL Commands Cheatsheet

Searchable openssl subcommand reference for certs, keys, digests and TLS testing

OpenSSL CLI cheatsheet covering req, x509, s_client, genrsa/genpkey, rsa, pkcs12, dgst and enc subcommands — each with a ready-to-run example for generating keys, CSRs, certificates and testing TLS endpoints.

How do I generate a private key and CSR with openssl?

Generate a key with openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out key.pem, then create a CSR with openssl req -new -key key.pem -out req.csr and answer the prompts (or pass -subj to fill them inline). Send the CSR to your certificate authority; keep key.pem secret.

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.