Skip to content

Instantly share code, notes, and snippets.

@idoop
Created December 1, 2022 05:16
Show Gist options
  • Save idoop/f1f2e9725cd1934ec7eb6602f7b0bd61 to your computer and use it in GitHub Desktop.
Save idoop/f1f2e9725cd1934ec7eb6602f7b0bd61 to your computer and use it in GitHub Desktop.
快速生成自签名证书的shell脚本
#!/bin/sh
# Date: 2022-12-01
# Author: ChenYang
country="CN"
province="Guangdong"
city="Shenzhen"
organization="Self-signed certificate"
ip="127.0.0.1"
domain="example.com"
main(){
which openssl || printf "\n Not found openssl command, please install frist\n" || exit 0
ssl_cnf="_san.cnf"
cat > ${ssl_cnf} <<EOF
[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
countryName = ${country}
stateOrProvinceName = ${province}
localityName = ${city}
organizationName = ${organization}
commonName = ${domain}
[req_ext]
subjectAltName = @alt_names
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = ${domain}
IP.1 = ${ip}
EOF
openssl req -new -nodes -x509 -days 3650 -keyout domain.pem.key -out domain.crt -config ${ssl_cnf}
rm ${ssl_cnf}
}
main
@idoop
Copy link
Author

idoop commented Dec 1, 2022

脚本中country,province,city,organization,ip,domain这些变量的值根据具体需求自行修改该即可.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment