Skip to content

Instantly share code, notes, and snippets.

@xcsrz
Last active October 28, 2015 23:19
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 xcsrz/b59f1d0c1c9675f3aa89 to your computer and use it in GitHub Desktop.
Save xcsrz/b59f1d0c1c9675f3aa89 to your computer and use it in GitHub Desktop.
This script creates the .key and .csr files using the bare minimum information. It's only argument is the domain name to be secured. Prepend "*." for wildcard domain certificates. Customize the DEFAULT_ORGNAME and DEFAULT_ORGCOUNTRY setting variables at the top before use. Environment variable overrides are ORGNAME and ORGCOUNTRY.
#!/bin/bash
DEFAULT_ORGNAME="xcsrz"
DEFAULT_ORGCOUNTRY="US"
if [ -t $1 ]; then
echo "you must provide a domain name (don't forget the asterisk if it's for a wildcard certificate"
echo ""
echo "Usage:"
echo " ${0} DOMAIN"
echo ""
exit 1
fi
: ${ORGNAME:=$DEFAULT_ORGNAME}
: ${ORGCOUNTRY:=$DEFAULT_ORGCOUNTRY}
filename=${1/\*/wildcard}
openssl req -nodes -newkey rsa:4096 -sha256 -keyout ${filename}.key -out ${filename}.csr -subj "/C=${ORGCOUNTRY}/O=${ORGNAME}/CN=${1}"
# openssl genrsa -out "${filename}.key" 4096
# openssl req -nodes -out "${filename}.csr" -key "${filename}.key" -new -sha256
echo "######################################################"
echo "#### Certificate Request Info (for verification): ####"
echo "#### ####"
echo ""
openssl req -in "${filename}.csr" -noout -text
echo "######################################################"
echo ""
echo "Make sure the above looks right before submitting to a Certificate Authority."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment