使用 openssl自动生成 证书脚本

方便以后使用整理个脚本

#!/usr/bin/expect

set pwd 888888
set hostname 0.0.0.0
set days 365
set mail [email protected]

spawn openssl genrsa -des3 -out "$hostname-pass.key" 2048

expect "Enter pass phrase for $hostname-pass.key:"
send "$pwd\r"
expect "Verifying - Enter pass phrase for $hostname-pass.key:"
send "$pwd\r"
interact

spawn openssl rsa -in "$hostname-pass.key" -out "$hostname.key"
expect "Enter pass phrase for $hostname-pass.key:"
send "$pwd\r"
interact

spawn openssl req  -new -x509 -key "$hostname.key" -out ca.crt -days $days -subj "/C=CN/ST=Hebei/L=Handan/O=$hostname/OU=ibeeger/CN=$hostname/emailAddress=$mail"
# expect "Enter pass phrase for $hostname.key:"
# send "$pwd\r"
interact


spawn openssl req -new -key "$hostname.key" -out server.csr -subj "/C=CN/ST=Hebei/L=Handan/O=$hostname/OU=ibeeger/CN=$hostname/emailAddress=$mail"
# expect "Enter pass phrase for $hostname.key:"
# send "$pwd\r"
interact


spawn openssl x509 -req -days $days -in server.csr -CA ca.crt -CAkey "$hostname.key" -CAcreateserial -out "$hostname.crt"
# expect "Enter pass phrase for $hostname.key:"
# send "$pwd\r"
interact

猜你喜欢

转载自blog.csdn.net/uk_51/article/details/104375479