A one-line OpenSSL command to generate a self-signed SSL certificate

Nick Scialli
December 06, 2022

Sometimes we just need to generate a self-signed SSL cert quickly with minimal fuss. In my experience, this has been helpful in development environment setup—but I’m sure there are plenty of good uses.

Here is the one-line shell script I use to:

openssl req  -nodes -new -x509  \
    -keyout ./cert/server.key \
    -out ./cert/server.cert \
    -subj "/C=US/ST=State/L=City/O=company/OU=Com/CN=www.testserver.local"

Okay, it’s several lines because I added line breaks for clarity, but you get the idea. With this command, you don’t get prompted for any additional information; the cert and private key are simply generated.

The key and cert are output in ./cert/server.key and ./cert/server.cert, respectively. Feel free to change those directories/filenames to better suit your needs.

If you'd like to support this blog by buying me a coffee I'd really appreciate it!

Nick Scialli

Nick Scialli is a senior UI engineer at Microsoft.

© 2024 Nick Scialli