A self-signed certificate made in this way is sufficient for testing, but should not be used in a production environment.
NOTE:
Ensure that openssl is installed.
sudo apt install openssl
NOTE: Look at the openssl man page to understand all of the openssl options.
man openssl
Create a self-signed certificate using the req command provided with OpenSSL:
openssl req -x509 -newkey rsa:2048 -keyout file1.key -out file2.crt -days 9999 -nodes
or
openssl req -new -x509 -days 9999 -nodes -out file1.pem -keyout file2.key
NOTE: Here, we name our certificate and key “file1” and “file2”, but when you have multiple certificates, they will require different names, or, should reside in different sub-directories of /etc/ssl.
This will prompt with a number of questions. Answer as appropriate.
Generating a 2048 bit RSA private key ...........................+++ ...........................................................................+++ writing new private key to 'my_cert.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]:JE State or Province Name (full name) [Some-State]:Jersey Locality Name (eg, city) []:St. Helier Organization Name (eg, company) [Internet Widgits Pty Ltd]:ShareWiz International Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:sharewiz.net Email Address []:admin@sharewiz.net
NOTE:
WARNING: we are now past the point where 9999 days takes us past the 32-bit Unix epoch.
The same code as above, but split into separate commands:
openssl req -new -out file1.pem -keyout file2.pem openssl rsa -in file2.pem -out www.key openssl req -x509 -in file1.pem -out www.crt -key www.key -days 3650
openssl req -new -x509 -days 3650 \ -newkey rsa:2048 -nodes -keyout test.key \ -out test.crt \ -subj '/C=PL/ST=example/O=ShareWiz/OU=test/CN=test'
chmod 600 file1* chmod 600 file2*