Generate self-signed SSL certificate in one line

If you need a quick self-signed certificate, you can generate the key/certificate pair, then sign it, all with one openssl line:

openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -out server.crt

Output:

root~#:/tmp/ssl$ openssl req -new -newkey rsa:2048 -days 365 -nodes -x5 09 -keyout server.key -out server.crt
Generating a 2048 bit RSA private key
…………………………………………………………………….. …………………………………………………………………….. …………………….+++
…..+++
writing new private key to ‘server.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]:IE
State or Province Name (full name) [Some-State]:Dublin
Locality Name (eg, city) []:Dublin
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Internet 4network Ltd
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:dump.4network.eu
Email Address []:
root~#:/tmp/ssl$ l
total 16
drwxr-xr-x 2 root root 4096 Jul 1 17:18 .
drwxrwxrwt 10 root root 4096 Jul 1 17:17 ..
-rw-r–r– 1 root root 1326 Jul 1 17:18 server.crt
-rw-r–r– 1 root root 1704 Jul 1 17:18 server.key
root~#:/tmp/ssl$

Leave a Reply

Your email address will not be published. Required fields are marked *

*