Created
November 17, 2011 02:55
-
-
Save kylelemons/1372236 to your computer and use it in GitHub Desktop.
Generate a key/certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: gencert.sh | |
# Generates SSL certificates | |
set -e | |
PREFIX="my_" | |
function oops() { | |
echo "Failed." | |
exit 1 | |
} | |
trap oops ERR | |
CERTFILE="${PREFIX}cert.pem" | |
PRIVKEY="${PREFIX}private.pem" | |
KEYFILE="${PREFIX}key.pem" | |
BITS=4096 | |
EXPIRE=$((365*10)) | |
echo Generating the private key... | |
openssl genrsa -des3 -passout pass:password -out $PRIVKEY $BITS >/dev/null 2>&1 | |
echo Decrypting the key... | |
openssl rsa -passin pass:password -in $PRIVKEY -out $KEYFILE >/dev/null 2>&1 | |
rm $PRIVKEY | |
echo Generating the certificate... | |
openssl req -new -x509 -key $KEYFILE -out $CERTFILE -days $EXPIRE >/dev/null 2>&1 <<EOF | |
<country> | |
<state> | |
<city> | |
<company> | |
<division> | |
<hostname> | |
<email> | |
EOF | |
# Make sure the world can't read it | |
chmod o-rwx $CERTFILE $KEYFILE | |
echo "Generated: $CERTFILE | $KEYFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment