Skip to main content

OpenSSL Commands Cheatsheet

A quick reference for common OpenSSL commands used for certificate management, key generation, encryption, and TLS debugging.

Certificate & Key Generation

CommandWhat It Does
openssl genrsa -out private.key 2048Generates a 2048-bit RSA private key.
openssl genrsa -aes256 -out private.key 4096Generates a 4096-bit RSA private key with AES-256 encryption (password-protected).
openssl ecparam -genkey -name prime256v1 -out ec.keyGenerates an EC private key using P-256 curve.
openssl req -new -key private.key -out request.csrCreates a Certificate Signing Request (CSR) from a private key.
openssl req -new -newkey rsa:2048 -nodes -keyout private.key -out request.csrGenerates a new private key and CSR in one command.
openssl req -x509 -newkey rsa:2048 -nodes -keyout private.key -out cert.pem -days 365Creates a self-signed certificate and key in one command.
openssl req -x509 -key private.key -in request.csr -out cert.pem -days 365Signs a CSR to create a self-signed certificate.

Certificate Inspection

CommandWhat It Does
openssl x509 -in cert.pem -text -nooutDisplays full certificate details in human-readable format.
openssl x509 -in cert.pem -subject -nooutShows the certificate subject (CN, O, OU, etc.).
openssl x509 -in cert.pem -issuer -nooutShows the certificate issuer.
openssl x509 -in cert.pem -dates -nooutShows certificate validity dates (notBefore, notAfter).
openssl x509 -in cert.pem -serial -nooutShows the certificate serial number.
openssl x509 -in cert.pem -fingerprint -sha256 -nooutShows the SHA-256 fingerprint of the certificate.
openssl x509 -in cert.pem -pubkey -nooutExtracts the public key from the certificate.
openssl x509 -in cert.der -inform DER -text -nooutReads a DER-encoded certificate.

CSR Inspection

CommandWhat It Does
openssl req -in request.csr -text -nooutDisplays the CSR contents.
openssl req -in request.csr -verify -nooutVerifies the CSR signature.
openssl req -in request.csr -subject -nooutShows the CSR subject.

Key Inspection & Management

CommandWhat It Does
openssl rsa -in private.key -checkChecks the consistency of an RSA private key.
openssl rsa -in private.key -text -nooutDisplays private key details.
openssl rsa -in private.key -pubout -out public.keyExtracts the public key from a private key.
openssl rsa -in encrypted.key -out decrypted.keyRemoves password protection from a private key.
openssl rsa -in private.key -aes256 -out encrypted.keyAdds password protection to a private key.
openssl ec -in ec.key -text -nooutDisplays EC private key details.

Format Conversion

CommandWhat It Does
openssl x509 -in cert.pem -outform DER -out cert.derConverts PEM to DER format.
openssl x509 -in cert.der -inform DER -outform PEM -out cert.pemConverts DER to PEM format.
openssl pkcs12 -export -out bundle.p12 -inkey private.key -in cert.pemCreates a PKCS12 bundle from key and certificate.
openssl pkcs12 -export -out bundle.p12 -inkey private.key -in cert.pem -certfile ca.pemCreates a PKCS12 bundle including CA chain.
openssl pkcs12 -in bundle.p12 -out all.pem -nodesExtracts all contents from PKCS12 to PEM.
openssl pkcs12 -in bundle.p12 -nocerts -out private.keyExtracts only the private key from PKCS12.
openssl pkcs12 -in bundle.p12 -clcerts -nokeys -out cert.pemExtracts only the client certificate from PKCS12.
openssl pkcs12 -in bundle.p12 -cacerts -nokeys -out ca.pemExtracts only CA certificates from PKCS12.

Certificate Verification

CommandWhat It Does
openssl verify -CAfile ca.pem cert.pemVerifies a certificate against a CA certificate.
openssl verify -CAfile ca.pem -untrusted intermediate.pem cert.pemVerifies with intermediate certificates.
openssl x509 -in cert.pem -noout -modulus | openssl md5Gets modulus hash to compare cert with key.
openssl rsa -in private.key -noout -modulus | openssl md5Gets modulus hash of private key for comparison.
openssl req -in request.csr -noout -modulus | openssl md5Gets modulus hash of CSR for comparison.

TLS/SSL Connection Testing

CommandWhat It Does
openssl s_client -connect host:443Tests TLS connection to a server.
openssl s_client -connect host:443 -showcertsShows all certificates in the chain.
openssl s_client -connect host:443 -servername hostTests with SNI (Server Name Indication).
openssl s_client -connect host:443 -tls1_2Forces TLS 1.2 connection.
openssl s_client -connect host:443 -tls1_3Forces TLS 1.3 connection.
openssl s_client -connect host:443 -cert client.pem -key client.keyTests mTLS connection with client certificate.
openssl s_client -connect host:443 -CAfile ca.pemVerifies server certificate against specific CA.
openssl s_client -connect host:443 -proxy proxy:8080Connects through an HTTP proxy.
openssl s_client -connect host:443 -starttls smtpTests STARTTLS for SMTP.
openssl s_client -connect host:443 -starttls imapTests STARTTLS for IMAP.
openssl s_client -connect host:443 < /dev/null 2>/dev/null | openssl x509 -noout -datesQuickly checks server certificate expiry.

Encryption & Hashing

CommandWhat It Does
openssl enc -aes-256-cbc -salt -in file.txt -out file.encEncrypts a file with AES-256-CBC.
openssl enc -aes-256-cbc -d -in file.enc -out file.txtDecrypts a file encrypted with AES-256-CBC.
openssl dgst -sha256 file.txtCalculates SHA-256 hash of a file.
openssl dgst -sha256 -sign private.key -out signature.bin file.txtSigns a file with a private key.
openssl dgst -sha256 -verify public.key -signature signature.bin file.txtVerifies a signature with a public key.
openssl rand -hex 32Generates 32 bytes of random hex data.
openssl rand -base64 32Generates 32 bytes of random base64 data.
echo -n "password" | openssl dgst -sha256Hashes a string with SHA-256.

Certificate Authority Operations

CommandWhat It Does
openssl ca -config ca.cnf -in request.csr -out cert.pemSigns a CSR using a CA configuration.
openssl ca -config ca.cnf -revoke cert.pemRevokes a certificate.
openssl ca -config ca.cnf -gencrl -out crl.pemGenerates a Certificate Revocation List (CRL).
openssl crl -in crl.pem -text -nooutDisplays CRL contents.

Debugging & Information

CommandWhat It Does
openssl version -aShows OpenSSL version and build configuration.
openssl ciphers -vLists all available cipher suites.
openssl ciphers -v 'TLSv1.3'Lists TLS 1.3 cipher suites.
openssl list -digest-algorithmsLists available digest algorithms.
openssl list -cipher-algorithmsLists available cipher algorithms.
openssl speed aes-256-cbcBenchmarks AES-256-CBC performance.
tip

Replace host with your actual hostname and adjust file paths as needed for your environment.