Skip to content

Instantly share code, notes, and snippets.

@hernandesbsousa
Forked from bradland/gencert.sh
Created October 4, 2013 20:13
Show Gist options
  • Save hernandesbsousa/6832038 to your computer and use it in GitHub Desktop.
Save hernandesbsousa/6832038 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Bash shell script for generating self-signed certs. Run this in a folder, as it
# generates a few files. Based on the following GIST Extract by Brad Landers:
# https://gist.github.com/bradland/1690807
#
# Additional alterations by: Hernandes B. de Sousa
# Date: 2013-10-04
#
# Script accepts a single argument, the fqdn for the cert
DOMAIN="$1"
COMPANY="$2"
if [ -z "$DOMAIN" ] || [ -z "$COMPANY" ]; then
echo "Usage: $(basename $0) <domain> <company>"
exit 11
fi
fail_if_error() {
[ $1 != 0 ] && {
exit 10
}
}
openssl genrsa -out $DOMAIN.key 4096;
fail_if_error $?
subj="
C=BR
ST=SP
O=$COMPANY
localityName=Sao Paulo
commonName=$DOMAIN
emailAddress=admin@example.com
"
openssl req \
-new \
-batch \
-subj "$(echo -n "$subj" | tr "\n" "/")" \
-key $DOMAIN.key \
-out $DOMAIN.csr
fail_if_error $?
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt;
fail_if_error $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment