Skip to Content

OpenSSL Commands Cheat Sheet

OpenSSL is the true Swiss Army knife of certificate management, and just like with the real McCoy, we spend more time extracting the nail file when what we really want is the inflatable hacksaw.

We will find an overview of the most commonly used commands below.

Certificate requests and key generation with OpenSSL

Typically, when we ordered a new SSL certificate we must generate a CSR or certificate signing request, with a new private key:

openssl req -sha256 -nodes -newkey rsa:2048 -kewet -out

Generate a new certificate request using an existing private key:

openssl req -new -sha256 -key -out

Generate a certificate request starting from an existing certificate:

openssl x509 -x509toreq -in -out -signkey

Generate a new RSA private key:

openssl genrsa -out 2048

Encrypt a private key with a passphrase:

openssl rsa -in -out -des3

Remove a passphrase from an encrypted private key:

openssl rsa -in -out

Generate a new ECC private key:

openssl ecparam -out server.key -name prime256v1 -genkey

Create a self-signed certificate with Openssl

Generate a self-signed certificate for testing purposes with one year validity period, together with a new 2048-bit key:

openssl req -x509 -newkey rsa:2048 -nodes -kewet -out -days 365

View and verify certificates with OpenSSL

Check and display a certificate request (CSR):

openssl req -noout -text -verify -in

Verify and display a key pair:

openssl rsa -noout -text -check -in

View a PEM-encoded certificate:

openssl x509 -noout -text -in

View a certificate encoded in PKCS#7 format:

openssl pkcs7 -print_certs -in

View a certificate and key pair encoded in PKCS#12 format:

openssl pkcs12 -info -in

Verify an SSL connection and display all certificates in the chain:

openssl s_client -connect

Control whether a certificate, a certificate request and a private key have the same public key:

openssl x509 -noout -modulus | openssl sha256

openssl req -noout -modulus | openssl sha256

openssl rsa -noout -modulus | openssl sha256

Check a certificate and its intermediate certificate chain for web server purposes:

openssl verify -purpose sslserver -CAfile certificatebundle.pem -verbose

Certificate conversion with OpenSSL

Conversion of PKCS#12 ( .pfx .p12, typically used on Microsoft Windows) files with private key and certificate to PEM (typically used on Linux):

openssl pkcs12 -nodes -in -out

Conversion of PEM to PKCS#12:

openssl pkcs12 -export -in -inkey -out

Conversion of PKCS#7 format ( .p7b .p7c ) to PEM:

openssl pkcs7 -print_certs -in -out

Conversion of PEM format to PKCS#7:

openssl crl2pkcs7 -nocrl -certfile -out

Conversion of DER (.crt .cer or .der) to PEM:

openssl x509 -inform der -in certificate.cer -out certificate.pem

Conversion from PEM to DER format:

openssl x509 -outform der -in certificate.pem -out certificate.cer

Check SSL Connections with OpenSSL

This will output the website’s certificate, including any intermediate certificates:

openssl s_client -connect