carlessanagustin
11/23/2017 - 9:49 AM

Generate SSL keys for httpS

Create HTTPS SSL certificate files - Usage: wget -O - https://bit.ly/2C5rjCW | bash

#!/usr/bin/env bash

declare -a arr=( "certs/web" )

Country_Name=ES
State_Name=Catalunya
Locality=Barcelona
Organization="Example Co"
Common_Name=www.example.com

function ssl_keys(){
  mkdir -p $1

  echo 'Generating a Private Key...'
  openssl genrsa -out $1/selfsigned.key 2048

  echo 'Generating a Self-Signed Certificate...'
  openssl req -new -x509 -sha256 -days 3650 \
      -subj "/C=$Country_Name/ST=$State_Name/L=$Locality/O=$Organization/CN=$Common_Name" \
      -key $1/selfsigned.key \
      -out $1/selfsigned.crt

  echo 'HTTPS Self-Signed Certificate...'
  openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
      -subj "/C=$Country_Name/ST=$State_Name/L=$Locality/O=$Organization/CN=$Common_Name" \
      -keyout $1/https.key \
      -out $1/https.crt

  echo 'Nginx Perfect Forward Secrecy Diffie-Hellman group...'
  openssl dhparam -dsaparam -out $1/dhparam.pem 4096
}

for i in "${arr[@]}"
do
   ssl_keys "$i"
done