Create a self-signed certificate

Generate a self-signed certificate and key with one command

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'

tool
openssl27 commands
tags
opensslsecurity

More openssl commands

  • openssl x509 -in cert.pem -noout -text | grep -E 'Subject:|Issuer:|Not (Before|After)|DNS:'

    Show subject, issuer, validity dates and SANs

  • openssl x509 -in cert.pem -noout -dates

    Print the notBefore and notAfter dates

  • openssl verify -CAfile ca.pem cert.pem

    Check the certificate chain against a CA bundle

  • diff <(openssl x509 -pubkey -noout -in cert.pem) <(openssl pkey -pubout -in key.pem) && echo 'MATCH'

    Compare public keys; prints MATCH if the certificate and private key are a pair

  • openssl pkcs12 -export -in cert.pem -inkey key.pem -certfile ca.pem -out bundle.p12 -name myalias

    Pack the certificate, key and CA into one .p12 file

all 27 openssl commands