Last active
August 29, 2015 14:13
-
-
Save atika/597e1ff02556c5f36b24 to your computer and use it in GitHub Desktop.
Self-Signed Certificate for Apache
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 | |
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