Skip to content

Instantly share code, notes, and snippets.

@sammcgeown
Last active August 27, 2020 15:05
Show Gist options
  • Save sammcgeown/e7f5af60f1cbf4ccc60c7bd8212fbf17 to your computer and use it in GitHub Desktop.
Save sammcgeown/e7f5af60f1cbf4ccc60c7bd8212fbf17 to your computer and use it in GitHub Desktop.
Create Self-signed Certificates for Docker TLS using OpenSSL
export HOST="scmg-sc2-docker-host"
export IP="10.176.144.191"
# Condensed from https://docs.docker.com/engine/security/https/#create-a-ca-server-and-client-keys-with-openssl
# Run these commands individually
openssl genrsa -aes256 -out ca-key.pem 4096
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
openssl genrsa -out server-key.pem 4096
openssl req -subj "/CN=$HOST" -sha256 -new -key server-key.pem -out server.csr
echo subjectAltName = DNS:$HOST,IP:$IP,IP:127.0.0.1 >> extfile.cnf
echo extendedKeyUsage = serverAuth >> extfile.cnf
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf
chmod -v 0400 ca-key.pem server-key.pem
chmod -v 0444 ca.pem server-cert.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment