Created
April 22, 2018 21:38
-
-
Save thusoy/1af3db143de41f03818aca145875cad3 to your computer and use it in GitHub Desktop.
Create a self-signed tls cert
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
#!/bin/bash | |
# Creates a self-signed certificate for a given domain name | |
set -e | |
if [ $# -ne 1 ]; then | |
echo "Usage: generate_cert.sh <domain-name>" | |
echo | |
echo "Generates a self-signed certificate for a given domain name." | |
echo | |
echo "Missing domain parameter" | |
exit 1 | |
fi | |
domain=$1 | |
private_key=$(openssl genrsa 2048) | |
csr=$(openssl req -new -key <(echo "$private_key") -subj "/C=/ST=/L=/O=/OU=/CN=$domain") | |
cert=$(openssl x509 -req -days 3650 -in <(echo "$csr") -sha256 -signkey <(echo "$private_key")) | |
echo "# Private key: " | |
echo "$private_key" | |
echo "# Certificate:" | |
echo "$cert" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment