Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Forked from polevaultweb/ssl.sh
Created January 31, 2018 21:00
Show Gist options
  • Save colorful-tones/ae98a78e790e63504933fae1889bb2f5 to your computer and use it in GitHub Desktop.
Save colorful-tones/ae98a78e790e63504933fae1889bb2f5 to your computer and use it in GitHub Desktop.
Easily create local SSL certificates for development sites that work with you own Certificate Authority https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
#!/bin/sh
if [ "$#" -ne 1 ]
then
echo "Usage: Must supply a domain"
exit 1
fi
DOMAIN=$1
cd ~/certs
openssl genrsa -out $DOMAIN.key 2048
openssl req -new -key $DOMAIN.key -out $DOMAIN.csr
cat > $DOMAIN.ext << EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = $DOMAIN
DNS.2 = $DOMAIN.192.168.1.19.xip.io
EOF
openssl x509 -req -in $DOMAIN.csr -CA ../myCA.pem -CAkey ../myCA.key -CAcreateserial \
-out $DOMAIN.crt -days 1825 -sha256 -extfile $DOMAIN.ext
@colorful-tones
Copy link
Author

Original Gist: https://gist.github.com/polevaultweb/c83ac276f51a523a80d8e7f9a61afad0

I use this for adding certificates to local sites with MAMP Pro

  1. Create your own Certificate Authority https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
  2. Create a directory certs in your root directory
  3. Download this bash file to your root
  4. Copy the file to /usr/local/bin/: mv ssl.sh /usr/local/bin/ssl
  5. Make it executable chmod u+x /usr/local/bin/ssl
  6. Call it anywhere like ssl mydomain.dev (follow the prompts as per https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/#creating-ca-signed-certificates)
  7. Add the cert to your host in MAMP Pro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment