If you want to generate certificates manually follow up to the Create Certificate with OpenSSL
in the next section.
This is more recommended way of doing since you don't have to do the manual labour and
free from the risk of human error.
The solution is using auto-generate tool called mkcert
.
It is written in go and work perfectly fine on almost every OS with super easy commands.
You can install mkcert
with their recommended ways.
Here's the link.
After installing, you can just type mkcert <your-domain-name-here>
to generate cert files.
Eg. for localhost
, type mkcert localhost
will create .key
and .pem
file for localhost
and you can just use any of your local development setup.
Fedora users can follow this link.
I suggest to follow the second method with
openSSL
I tried the first method and I didn't succeed. Maybe you can.
- Generate Private Key
openssl genrsa -des3 -out rootCA.key 2048
- Generate Root Certificate
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 -out rootCA.pem
Enter pass phrase for myCA.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CA
State or Province Name (full name) [Some-State]:Nova Scotia
Locality Name (eg, city) []:Truro
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Delicious Brains Inc
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:Delicious Brains
Email Address []:[email protected]
- Convert
.pem
file to.crt
(Certificate) file
openssl x509 -in rootCA.pem -inform PEM -out rootCA.crt
- Install converted certificate
sudo mkdir /usr/share/ca-certificates/extra
sudo cp rootCA.crt /usr/share/ca-certificates/extra
sudo update-ca-certificates #Ubuntu
sudo update-ca-trust #Arch/Manjaro
# OR
sudo trust extract-compact #Arch/Manjaro
- Create CA-Signed Certificate for Dev Site
openssl genrsa -out your-dev-site-name.key 2048
Replace
your-dev-site-name
with your local dev domaineg.
localhost
- Making
csr
openssl req -new -key your-dev-site-name.key -out your-dev-site-name.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CA
State or Province Name (full name) [Some-State]:Nova Scotia
Locality Name (eg, city) []:Truro
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Delicious Brains Inc
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:Mergebot
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
- Creating
domains.ext
(extension for sub alternative name) file
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = dev.deliciousbrains.com
Replace
your-dev-site-name
with your local dev domaineg.
localhost
- Create certificate file
openssl x509 -req -in your-dev-site-name.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial \
-out your-dev-site-name.crt -days 825 -sha256 -extfile domains.ext
How to Create Your Own SSL Certificate Authority for Local HTTPS Development
How do I install a root certificate? - Ask Ubuntu
How do i import a Trusted Root Certificate - Newbie Corner - Manjaro Linux Forum
I just released lodev, single binary that provides easy setup for local development env with SSL (HTTPS).
It will create local CA, install it as a trusted CA and generate certificate and key. Spin up small DNS server that is used only to resolve dev.lo domain and create reverse proxy on port 443 under
https://dev.lo
domain and by default proxy all requests tohttp://localhost:3000
, target port can be changed.