Skip to content

Instantly share code, notes, and snippets.

@thesuhu
Created December 25, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesuhu/59dc0f2825986f0118baf0836c9b54ab to your computer and use it in GitHub Desktop.
Save thesuhu/59dc0f2825986f0118baf0836c9b54ab to your computer and use it in GitHub Desktop.
Generate Self SIgned Certificate With IP Address
#!/bin/sh
IP=$(echo $1 | egrep -o "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$")
if [ ! $IP ]
then
echo "Usage: generate-ip-cert.sh 127.0.0.1"
exit 1
fi
echo "[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
countryName = XX
stateOrProvinceName = N/A
localityName = N/A
organizationName = Self-signed certificate
commonName = $IP: Self-signed certificate
[req_ext]
subjectAltName = @alt_names
[v3_req]
subjectAltName = @alt_names
[alt_names]
IP.1 = $IP
" > san.cnf
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout key.pem -out cert.pem -config san.cnf
rm san.cnf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment