Created
December 25, 2022 15:50
-
-
Save thesuhu/59dc0f2825986f0118baf0836c9b54ab to your computer and use it in GitHub Desktop.
Generate Self SIgned Certificate With IP Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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