Last active
September 27, 2016 04:36
-
-
Save user454322/9404715 to your computer and use it in GitHub Desktop.
Script to create SSL self signed 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
#!/usr/bin/env bash | |
set -o errexit | |
## Functions | |
function usage(){ | |
echo "Usage: $0 -d <domain> [-t <time_in_days>]" | |
} | |
## Get options | |
while getopts "d:t:" option | |
do | |
case "${option}" | |
in | |
d) DOMAIN=${OPTARG};; | |
t) DAYS=${OPTARG};; | |
esac | |
done | |
if [ "x${DOMAIN}" == "x" ] | |
then | |
usage | |
exit 1; | |
fi | |
if [ "x${DAYS}" == "x" ] | |
then | |
DAYS="365" | |
fi | |
## Execute | |
openssl genrsa -out "$DOMAIN".key 2048 | |
openssl req -new -x509 -key "$DOMAIN".key -out "$DOMAIN".crt -days "$DAYS" -subj /CN="$DOMAIN" | |
chmod 0640 "$DOMAIN".key | |
cat "$DOMAIN".key "$DOMAIN".crt > "$DOMAIN".pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment