Skip to content

Instantly share code, notes, and snippets.

@koteq
Created September 25, 2017 14:57
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 koteq/69f6496992bb40f68f976caa6b3a85ac to your computer and use it in GitHub Desktop.
Save koteq/69f6496992bb40f68f976caa6b3a85ac to your computer and use it in GitHub Desktop.
openssl self-signed certificate creation for web server
set -e
if [ -z "$1" ]; then
hostname="$HOSTNAME"
else
hostname="$1"
fi
local_openssl_config="
[req]
prompt = no
x509_extensions = v3_req
distinguished_name = dn
[v3_req]
basicConstraints = CA:true
subjectAltName = @alt_names
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
[dn]
CN = $hostname
[alt_names]
DNS.1 = $hostname
DNS.2 = *.$hostname
"
openssl req \
-newkey rsa:2048 -nodes \
-keyout "$hostname.key" \
-x509 -sha256 -days 3650 \
-config <(echo "$local_openssl_config") \
-out "$hostname.crt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment