Skip to content

Instantly share code, notes, and snippets.

@amdelamar
Created October 19, 2017 16:43
Show Gist options
  • Save amdelamar/e5ec0945f8617364a9bfaa6901370806 to your computer and use it in GitHub Desktop.
Save amdelamar/e5ec0945f8617364a9bfaa6901370806 to your computer and use it in GitHub Desktop.
Generates a Self-Signed certificate and private key
#!/usr/bin/env sh
# Generates a Self-Signed Certificate and private key.
# Optionally, add a password as an argument.
# Argument 1 can be a Password
if [ "$1" == "" ]
then
# No Password
echo 'Creating Key and Cert without a Password...'
openssl genrsa -out privkey.pem 4096
openssl req -new -x509 -days 1826 -key privkey.pem -out cert.pem -subj "//C=US/ST=-/L=-/O=Test/OU=Test/CN=IT/emailAddress=info@example.com"
else
# With a Password
echo 'Creating Key and Cert with Password...'
openssl genrsa -des3 -passout pass:$1 -out privkey.pem 4096
openssl req -new -x509 -days 1826 -key privkey.pem -out cert.pem -passin pass:$1 -subj "//C=US/ST=-/L=-/O=Test/OU=Test/CN=IT/emailAddress=test@test.com"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment