Generate a self-signed certificate with OpenSSL

Published 27 Aug 2020

    Although not really useful in production, generating a self-signed certificate can be a great way to test the HTTPs functionality of on application locally.

    To generate a self signed certificate you'll need to have OpenSSL installed. Once that's done, creating the certificate is as easy as running the following in your terminal:

    openssl req -newkey rsa:2048 \
                -nodes \
                -keyout private_key.pem \
                -x509 \
                -days 365 \
                -out certificate.pem

    It will create two files. A private key file private_key.pem (used by your server/application to sign responses), and a certificate certificate.pem, which is used by clients to encrypt requests and verify the origin of the data.


    Personal notebook
    Andrea Tupini