Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ThisIsNoahEvans/4200d30183c8ed6675c4dc8b4bea8712 to your computer and use it in GitHub Desktop.
Save ThisIsNoahEvans/4200d30183c8ed6675c4dc8b4bea8712 to your computer and use it in GitHub Desktop.
Generate self-signed SSL certs & keys from a script

I usually use this for generating SSL certificates for IP addresses - such as internally hosted applications, so they can be secured properly. You will need to manually install and trust the certificate on all clients that wish to access the service with SSL, and provide the cert & key to the service.

This is not a guide! It is simply a script I wrote in about 5 minutes to quickly generate certificates for IP addresses. It is very badly written but it works. Just about.

I won't be maintaining this unless the entire premise of SSL and self-signed certificates magically breaks overnight.

#!/bin/bash
echo ":: Enter IP: "
read IP
echo "[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
countryName = GB
stateOrProvinceName = N/A
localityName = N/A
organizationName = N/A
commonName = $IP: N/A
[req_ext]
subjectAltName = @alt_names
[v3_req]
subjectAltName = @alt_names
[alt_names]
IP.1 = $IP" >> ssl-config-$IP
echo "Generating certificate..."
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout KEY-$IP.pem -out CERT-$IP.pem -config ssl-config-$IP >> /dev/null
rm ssl-config-$IP
echo "!! Certificate generated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment