Skip to content

Instantly share code, notes, and snippets.

@spareslant
Last active June 28, 2020 19:56
Show Gist options
  • Save spareslant/92b64de8397332e14f7fc01f30ddd59c to your computer and use it in GitHub Desktop.
Save spareslant/92b64de8397332e14f7fc01f30ddd59c to your computer and use it in GitHub Desktop.
non-interactive self signed CA and Server cert generation
#! /bin/bash
CERTS_DIR=/tmp/myCerts
rm -rf $CERTS_DIR
mkdir -p $CERTS_DIR
CN_NAME="192.168.0.20"
CA_DOMAIN="${CN_NAME}"
ALT_IP="${CN_NAME}"
echo "***** Create OpenSSL certificate and key ******"
cd ${CERTS_DIR}
openssl genrsa -out rootCA.key 4096
echo "======= Generate CA ========="
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -subj "/C=UK/ST=London/L=London/O=PlatformEngg/OU=Engg/CN=${CA_DOMAIN}" -out ca.pem
echo "======== Generate CSR ========"
openssl genrsa -out server_key.pem 2048
openssl req -new -sha256 -key server_key.pem \
-subj "/C=UK/ST=London/L=London/O=PlatformEngg/OU=Engg/CN=${CN_NAME}" \
-reqexts SAN -extensions SAN \
-config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=IP:${ALT_IP}")) \
-out server.csr
echo "======== Sign CSR with CA and create CERT========"
openssl x509 -req -in server.csr -CA ca.pem -CAkey rootCA.key -CAcreateserial -out server_cert.pem -days 365 -sha256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment