Skip to content

Instantly share code, notes, and snippets.

@user454322
Last active September 27, 2016 04:36
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 user454322/9404715 to your computer and use it in GitHub Desktop.
Save user454322/9404715 to your computer and use it in GitHub Desktop.
Script to create SSL self signed certificate
#!/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