Skip to content

Instantly share code, notes, and snippets.

@nathanborror
Last active October 8, 2016 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanborror/df6491debd1c86e40eb737751523350a to your computer and use it in GitHub Desktop.
Save nathanborror/df6491debd1c86e40eb737751523350a to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Generate RSA certificate and key
#
# The 'host' is the host on which the server is listening and 'prefix' is just
# used to prefix the output files.
#
# $ gen.sh <host> <prefix>
#
PASSWORD=`LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1`
HOST=$1
if [ -z $HOST ]; then HOST="localhost"; fi
PREFIX=$2
if [ -z $PREFIX ]; then PREFIX="dev"; fi
openssl genrsa -passout pass:${PASSWORD} -des3 -out "${PREFIX}_server.key" 4096
openssl req -passin pass:${PASSWORD} -new -x509 -days 3650 -key "${PREFIX}_server.key" -out "${PREFIX}_server.crt" -subj '/C=US/ST=CA/L=PaloAlto/O=MyApp/CN='${HOST}'/emailAddress=nathan@nathanborror.com'
openssl rsa -passin pass:${PASSWORD} -in "${PREFIX}_server.key" -out "${PREFIX}_server.key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment