Create a self-signed TLS certificate for your local development

When you are developing an applicaiton on your localhost and want to access and test it through a secure connection you will need a certificate. Requesting one from a 3rd party service will cost you money, so here is the way to create a self-signed certificate by yourself. Bear in mind you could use it only for testing purposes and will not be able to validate it against 3rd party authorities.

1. Create the certificate by issuing the followig line:

openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out public.crt -keyout private.key

Once executed the command will lead you through a set of questions in order to generate the certificate as requested. You will be presented with a screen similar to the one below:

Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

2. Secure the private key:

chmod 400 private.key

As a result of the above commands two files will be generated in your current folder: the public certificate and the related private key.