Skip to content

Instantly share code, notes, and snippets.

@guimaluf
Last active June 13, 2017 18:30
Show Gist options
  • Save guimaluf/392cf07cf9f8f7241da993b3c9e1e9ab to your computer and use it in GitHub Desktop.
Save guimaluf/392cf07cf9f8f7241da993b3c9e1e9ab to your computer and use it in GitHub Desktop.
Simple bash script for generating self-signed certificates with wildcard
#!/bin/bash
function usage {
echo "usage: $0 hostname"
exit 0
}
HOSTNAME=$1
[ -z ${HOSTNAME} ] && usage
SERVER_KEY=${HOSTNAME}.key
SERVER_CERT=${HOSTNAME}.crt
DAYS=$((365*10))
SUBJECT="/C=BR/ST=RN/L=Natal/O=Anolis/CN=${HOSTNAME}"
openssl req -new -newkey rsa:2048 -nodes -x509 -sha256 \
-days ${DAYS} \
-subj "${SUBJECT}" \
-keyout ${SERVER_KEY} \
-reqexts SAN -extensions SAN \
-config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:*.${HOSTNAME}")) \
-out ${SERVER_CERT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment