Skip to content

Instantly share code, notes, and snippets.

@thusoy
Created April 22, 2018 21:38
Show Gist options
  • Save thusoy/1af3db143de41f03818aca145875cad3 to your computer and use it in GitHub Desktop.
Save thusoy/1af3db143de41f03818aca145875cad3 to your computer and use it in GitHub Desktop.
Create a self-signed tls cert
#!/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