Created
September 25, 2017 14:57
-
-
Save koteq/69f6496992bb40f68f976caa6b3a85ac to your computer and use it in GitHub Desktop.
openssl self-signed certificate creation for web server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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