Skip to content

Instantly share code, notes, and snippets.

@e7d
Last active May 18, 2021 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e7d/9b4e02a77771ac062568776f53795880 to your computer and use it in GitHub Desktop.
Save e7d/9b4e02a77771ac062568776f53795880 to your computer and use it in GitHub Desktop.
Generate self-signed certificate with OpenSSL
#!/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