Created
December 1, 2022 05:16
-
-
Save idoop/f1f2e9725cd1934ec7eb6602f7b0bd61 to your computer and use it in GitHub Desktop.
快速生成自签名证书的shell脚本
This file contains hidden or 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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
脚本中
country
,province
,city
,organization
,ip
,domain
这些变量的值根据具体需求自行修改该即可.