TypeOfNaN

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

Nick Scialli
December 06, 2022

New — Check out my free newsletter on how the web works!

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:

#!/bin/bash
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.

🎓 Learn how the web works

One of the best ways to level up your tech career is to have a great foundational understanding of how the web works. In my free newsletter, How the Web Works, I provide simple, bite-sized explanations for various web topics that can help you boost your knowledge. Join 2,500+ other learners on the newsletter today!

Signing up is free, I never spam, and you can unsubscribe any time. You won't regret it!

Sign up for the newsletter »
Nick Scialli

Nick Scialli is a senior UI engineer at Microsoft.

© 2024 Nick Scialli