Last active
May 18, 2021 13:40
-
-
Save e7d/9b4e02a77771ac062568776f53795880 to your computer and use it in GitHub Desktop.
Generate self-signed certificate with 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
#!/bin/bash | |
# read input | |
domain=$1 | |
if [ -z $domain ]; then | |
read -p "domain: " domain | |
fi | |
rsa=$2 | |
if [ -z $rsa ]; then | |
rsa=2048 # 2048 bits by default | |
fi | |
days=$3 | |
if [ -z $days ]; then | |
days=3650 # 10 years by default | |
fi | |
# generate key pair | |
openssl \ | |
req \ | |
-sha256 \ | |
-newkey rsa:$rsa \ | |
-x509 \ | |
-nodes \ | |
-keyout $domain.key \ | |
-out $domain.pem \ | |
-days $days \ | |
-subj "/CN=$domain" | |
# check results | |
openssl x509 -in $domain.pem -text -noout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment