Last active
July 24, 2021 14:22
-
-
Save J-Rios/8e015ce5a2a0d37d97e2fd652bafe790 to your computer and use it in GitHub Desktop.
Generate a self-signed certificates using openssl
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
#!/usr/bin/env bash | |
############################################################################### | |
PASSPHRASE="password1234" | |
LANG="ES" | |
LOCATION="Malaga" | |
CITY="Malaga" | |
COMPANY="Open Source" | |
DAYS="3650" | |
############################################################################### | |
# Check for Requeriments | |
curl -V > /dev/null 2>&1 | |
if [[ $? != 0 ]]; then | |
echo "Error: curl not found, please install it (i.e. apt-get install curl)" | |
echo "" | |
exit 1 | |
fi | |
openssl version > /dev/null 2>&1 | |
if [[ $? != 0 ]]; then | |
echo "Error: openssl not found, please install it (i.e. apt-get install openssl)" | |
echo "" | |
exit 1 | |
fi | |
############################################################################### | |
# Get Public IP address | |
MYIP=`curl -s https://ipinfo.io/ip` | |
if [[ $? != 0 ]]; then | |
echo "Error: Can't get host IP address (no network or https://ipinfo.io is down)." | |
echo "" | |
exit 1 | |
fi | |
# Remove any previous certs files | |
rm -f ./cert.pem | |
rm -f ./private.key | |
# Check and create random file if it doesn't exists (fix openssl issue...) | |
if [ ! -f ~/.rnd ]; then | |
openssl rand -out ~/.rnd -hex 256 | |
fi | |
# Create the Certificate | |
openssl req -newkey rsa:4096 \ | |
-x509 \ | |
-sha256 \ | |
-days $DAYS \ | |
-nodes \ | |
-passin pass:$PASSPHRASE \ | |
-out cert.pem \ | |
-keyout private.key \ | |
-subj "/C=${LANG}/ST=${LOCATION}/L=${CITY}/O=${COMPANY}/CN=$MYIP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment