Generate CSRs, Certificates, Private Keys and other tasks.
Generate a new private key and Certificate Signing Request
# openssl req -out mydomain.csr -new -newkey rsa:2048 -nodes -keyout mydomain.key
Generate a self-signed certificate
# openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout mydomain.key -out mydomain.crt
Generate a certificate signing request (CSR) for an existing private key
# openssl req -out mydomain.csr -key mydomain.key -new
Generate a certificate signing request based on an existing certificate
# openssl x509 -x509toreq -in mydomain.crt -out mydomain.csr -signkey mydomain.key
Remove a passphrase from a private key
# openssl rsa -in mydomain.key -out new_mydomain.key
Add a passphrase to a private key
# openssl rsa -aes256 -in mydomain.key -out new_mydomain.key
Checking Using OpenSSL
If you need to check the information within a Certificate, CSR or Private Key, use these commands.
Check a Certificate Signing Request (CSR)
# openssl req -text -noout -verify -in mydomain.csr
Check a private key
# openssl rsa -in mydomain.key -check
Check a certificate
# openssl x509 -in mydomain.crt -text -noout
Check a PKCS#12 file (.pfx or .p12)
# openssl pkcs12 -info -in key.p12
Debugging Using OpenSSL
If you are receiving an error that the private doesn't match the certificate or that a certificate is not trusted, try one of these commands.
Check an MD5 hash of the public key to ensure that it matches with what is in a CSR or private key
# openssl x509 -noout -modulus -in mydomain.crt | openssl md5
# openssl rsa -noout -modulus -in mydomain.key | openssl md5
# openssl req -noout -modulus -in mydomain.csr | openssl md5
Check an SSL connection. All the certificates (including Intermediates) should be displayed
# openssl s_client -connect mo.homelinux.net:443
Converting Using OpenSSL
These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software. For example, you can convert a normal PEM file that would work with Apache to a PFX (PKCS#12) file.
Convert a DER (.crt .cer .der) to PEM
# openssl x509 -inform der -in mydomain.cer -out mydomain.pem
Convert a PEM to DER
# openssl x509 -outform der -in mydomain.pem -out mydomain.der
Convert a PKCS#12 (.pfx .p12) containing a private key and certificates to PEM
# openssl pkcs12 -in keys.pfx -out keys.pem -nodes
You can add -nocerts to only output the private key or add -nokeys to only output the certificates.
Convert a PEM certificate and a private key to PKCS#12 (.pfx .p12)
# openssl pkcs12 -export -out mydomain.pfx -inkey mydomain.key -in mydomain.crt -certfile ca.crt