Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevin-smets/b745167d1522b429f7eb8cfdb23b7cfa to your computer and use it in GitHub Desktop.
Save kevin-smets/b745167d1522b429f7eb8cfdb23b7cfa to your computer and use it in GitHub Desktop.
Creating a Self-Signed SSL Certificate

Create a secrets file:

touch ~/.secret

Make sure it looks like this:

#!/bin/bash
PASSPHRASE=mysecretpassphrase

And source it:

. ~/.secret
openssl genrsa -des3 -passout pass:$PASSPHRASE -out server.pass.key 2048;
openssl rsa -passin pass:$PASSPHRASE -in server.pass.key -out server.key;
openssl req -new -key server.key -out server.csr;
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt;

# Remove the unencrypted private key
rm server.key

Test your generated and encrypted private key:

openssl rsa -in server.pass.key -text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment