OpenSSL Commands Reference
Essential OpenSSL commands for certificate management and troubleshooting
📋 Inspecting Certificates
View certificate details (PEM format)
openssl x509 -in certificate.crt -text -nooutDisplays all certificate information including subject, issuer, validity dates, and extensions.
View certificate details (DER format)
openssl x509 -in certificate.der -inform DER -text -nooutCheck certificate expiration date
openssl x509 -in certificate.crt -noout -datesView certificate subject and issuer
openssl x509 -in certificate.crt -noout -subject -issuerCheck certificate fingerprint (SHA256)
openssl x509 -in certificate.crt -noout -fingerprint -sha256📝 Certificate Signing Request (CSR) Operations
Generate private key and CSR (RSA 2048-bit)
openssl req -newkey rsa:2048 -keyout private.key -out request.csrCreates both a new private key and CSR. You'll be prompted for information and a passphrase.
Generate CSR from existing private key
openssl req -new -key private.key -out request.csrView CSR details
openssl req -in request.csr -text -nooutVerify CSR signature
openssl req -in request.csr -verify -noout🔄 Format Conversion
Convert PEM to DER
openssl x509 -in certificate.crt -outform DER -out certificate.derConvert DER to PEM
openssl x509 -in certificate.der -inform DER -out certificate.crtConvert PFX to PEM (certificate and key)
openssl pkcs12 -in certificate.pfx -out certificate.pem -nodesExtract both certificate and private key. Remove -nodes to encrypt the private key.
Convert PFX to PEM (certificate only)
openssl pkcs12 -in certificate.pfx -clcerts -nokeys -out certificate.crtConvert PFX to PEM (private key only)
openssl pkcs12 -in certificate.pfx -nocerts -out private.keyCreate PFX from PEM certificate and key
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt🔑 Private Key Operations
Generate RSA private key (2048-bit)
openssl genrsa -out private.key 2048Generate encrypted RSA private key (4096-bit)
openssl genrsa -aes256 -out private.key 4096Generate EC private key (P-256)
openssl ecparam -genkey -name prime256v1 -out private.keyRemove passphrase from private key
openssl rsa -in encrypted.key -out decrypted.keyAdd passphrase to private key
openssl rsa -in private.key -aes256 -out encrypted.keyView private key details
openssl rsa -in private.key -text -noout🔒 Testing SSL/TLS Connections
Test SSL/TLS connection and view certificate
openssl s_client -connect example.com:443 -showcertsTest with specific TLS version
openssl s_client -connect example.com:443 -tls1_2Replace -tls1_2 with -tls1_3 for TLS 1.3
Download server certificate
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 > server.crtCheck certificate with SNI (Server Name Indication)
openssl s_client -connect example.com:443 -servername example.comShow protocol messages and DNs (Distinguished Names)
openssl s_client -connect example.com:443 -msgDisplays all TLS protocol messages including certificate request DNs. Useful for debugging client certificate authentication and seeing which CAs the server trusts.
Test SMTP STARTTLS
openssl s_client -connect mail.example.com:25 -starttls smtp✅ Verification and Validation
Verify certificate matches private key
openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in private.key | openssl md5Both commands should output the same MD5 hash if they match.
Verify certificate chain
openssl verify -CAfile ca-bundle.crt certificate.crtVerify certificate chain with intermediate certificates
openssl verify -CAfile root.crt -untrusted intermediate.crt certificate.crt🛠️ Self-Signed Certificates (Testing/Development)
Generate self-signed certificate (valid 365 days)
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365Generate self-signed certificate with no password
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodesGenerate self-signed certificate with SAN (Subject Alternative Names)
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=example.com" \
-addext "subjectAltName=DNS:example.com,DNS:www.example.com"