Last active
February 15, 2020 16:22
-
-
Save Alex1990/e1c1025d5c0677f82b639659f42f8417 to your computer and use it in GitHub Desktop.
Generate a self-signed ssl certificate
This file contains 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
#!/usr/bin/env bash | |
# The "Common Name (CN)" can be "example.com" or "*.example.com www.example.com" | |
# This command should be executed in non-root mode | |
domain="$1" | |
if [ -z "$domain" ]; then | |
echo "need domain parameter" | |
exit 1 | |
fi | |
san=$(cat <<-END | |
[SAN] | |
subjectAltName=@alt_names | |
[alt_names] | |
DNS.1=$domain | |
END | |
) | |
openssl req \ | |
-newkey rsa:2048 \ | |
-x509 \ | |
-nodes \ | |
-keyout "${domain}.key" \ | |
-new \ | |
-out "${domain}.crt" \ | |
-reqexts SAN \ | |
-extentions SAN \ | |
-config <(cat /System/Library/OpenSSL/openssl.cnf \ | |
<(echo "$san")) \ | |
-sha256 \ | |
-days 365 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
*.crt
or*.pem
.