Skip to content

Instantly share code, notes, and snippets.

@atika
Last active August 29, 2015 14:13
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 atika/597e1ff02556c5f36b24 to your computer and use it in GitHub Desktop.
Save atika/597e1ff02556c5f36b24 to your computer and use it in GitHub Desktop.
Self-Signed Certificate for Apache
#!/bin/bash
servername=$(echo "$@" |sed 's/ /-/g')
if [ "$servername" == "" ]; then
echo "Please specify a server name like: myserver.com"
exit
fi
if [ -f "$servername.key" ] || [ -f "$servername.crt" ]; then
echo "A key with this server name already exist, aborting…"
exit
fi
cyan="\\033[1;36m"
normal="\\033[39m"
# Private Key Gen (key)
echo -e "[$cyan SSL $normal] Generate Private Key"
openssl genrsa -des3 -out $servername.key 2048
# Certificate Signin Request (csr)
echo -e "[$cyan SSL $normal] Generate Certificate Signin Request"
openssl req -new -key $servername.key -out $servername.csr
# Remove passphrase
echo -e "[$cyan SSL $normal] Remove passphrase from key"
cp $servername.key $servername.key.org
openssl rsa -in $servername.key.org -out $servername.key
# Self Signed Certificate
echo -e "[$cyan SSL $normal] Generate Self-Signed Certificate"
openssl x509 -req -days 3650 -in $servername.csr -signkey $servername.key -out $servername.crt
# Key has no passphrase protect them
echo -e "[$cyan SSL $normal] Change authorization generated key and certificate"
echo -e "Verify that generated elements are$cyan only readable by root$normal"
echo -e "You an install""$cyan""$servername.crt and $servername.key""$normal"
chmod 644 $servername.{key,crt,csr}
ls -lis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment