This is the key used to sign the certificate requests, anyone has this can sign certificates on your behalf. So keep it extremely safe!
openssl genrsa -des3 -out rootCA.key 4096
or without a password protection
openssl genrsa -out rootCA.key 4096
Now we use the created root key to create a root certificate that will be distributed in all the computers that have to trust us.
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1095 -out rootCA.crt -config certificate.conf
We need to do this for each server that needs a trusted certificate from our CA
openssl genrsa -out bindiegoserver.com.key 2048
The request is where we specify the details for the certificate we want to generate. This request should be processed by the owner of the Root key to generate the certificate.
Important: It's very important to specify the Common Name by providing IP address or domain name for the service, otherwise the certificate cannot be verified.
openssl req -new -sha256 -key bindiegoserver.com.key -subj "/C=US/ST=CA/O=Elastic, Inc./CN=bindiegoserver.com" -out bindiegoserver.com.csr
Or you may want to pass additional config, you can use the -config parameter, here for instance you can add alternative names to the certificate.
openssl req -new -sha256 \
-key bindiegoserver.com.key \
-subj "/C=US/ST=CA/O=Elastic, Inc./CN=bindiegoserver.com" \
-reqexts SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "\n[SAN]\nsubjectAltName=DNS:bindiegoserver.com,DNS:www.bindiegoserver.com")) \
-out bindiegoserver.com.csr
openssl req -in bindiegoserver.com.csr -noout -text
openssl x509 -req -in bindiegoserver.com.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out bindiegoserver.com.crt -days 365 -sha256
openssl x509 -in bindiegoserver.com.crt -text -noout