Skip to content

Instantly share code, notes, and snippets.

@renier
Created October 30, 2016 08:06
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 renier/f54eed9f8e25f3ae1a71ee6449008ef8 to your computer and use it in GitHub Desktop.
Save renier/f54eed9f8e25f3ae1a71ee6449008ef8 to your computer and use it in GitHub Desktop.
Generate an SSL certificate
#!/bin/bash
DOMAIN=$(hostname -f)
export PASSPHRASE=$(head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 128; echo)
subj="
C=$1
ST=$2
O=$3
localityName=$4
commonName=$DOMAIN
organizationalUnitName=$5
emailAddress=$6
"
openssl genrsa -des3 -out cert.key -passout env:PASSPHRASE 2048
openssl req \
-new \
-batch \
-subj "$(echo -n "$subj" | tr "\n" "/")" \
-key cert.key \
-out cert.csr \
-passin env:PASSPHRASE
cp cert.key cert.key.orig
openssl rsa -in cert.key.orig -out cert.key -passin env:PASSPHRASE
openssl x509 -req -days 3650 -in cert.csr -signkey cert.key -out cert.crt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment