[root@yc1 ~]# cat yc_https.sh #!/bin/bash hostname=192.168.23.140 rm -rf /etc/pki/CA &>/dev/null mkdir -p /etc/pki/CA/privatr cd /etc/pki/CA yum -y install expect echo '生成CA的公钥' (umask 077;openssl genrsa -out private/cakey.pem 2048) echo '提取CA的公钥' openssl rsa -in private/cakey.pem -pubout echo '生成签署证书' expect << EOF set timeout 30 spawn openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 100 expect "letter code" {send "cn\r"} expect "full name" {send "HB\r"} expect "city" {send "WH\r"} expect "company" {send "runtime\r"} expect "section" {send "teach\r"} expect "hostname" {send "${hostname}\r"} expect "Email" {send "1@2.com\r"} expect "#" EOF echo '完成签署证书' sleep 5s openssl x509 -text -in cacert.pem mkdir certs newcerts crl touch index.txt && echo 01 > serial #需要安装httpd服务 yum -y remove httpd &>/dev/null yum -y install httpd &>/dev/null systemctl enable --now httpd &>/dev/null echo 'httpd服务生成密钥中!' cd /etc/httpd && mkdir ssl && cd ssl (umask 077;openssl genrsa -out httpd.key 2048) echo '生成证书签署请求' expect << EOF set timeout 30 spawn openssl req -new -key httpd.key -days 365 -out httpd.csr expect "letter code" {send "cn\r"} expect "full name" {send "HB\r"} expect "city" {send "WH\r"} expect "company" {send "runtime\r"} expect "section" {send "teach\r"} expect "hostname" {send "${hostname}\r"} expect "Email" {send "yc@yc.com\r"} expect "password" {send "\r"} expect "company name" {send "\r"} expect "#" EOF echo '完成请求' sleep 5s echo '签署证书中!' expect << EOF set timeout 30 spawn openssl ca -in ./httpd.csr -out httpd.crt -days 365 expect "certificate" {send "y\r"} expect "commit" {send "y\r"} expect "#" EOF echo '完成签署' sleep 5s echo '修改配置文件中' yum -y remove mod_ssl &>/dev/null yum -y install mod_ssl &>/dev/null sed -i "s/#DocumentRoot/DocumentRoot/g" /etc/httpd/conf.d/ssl.conf sed -i "s/#ServerName www.example.com:443/ServerName ${hostname}:443/g" /etc/httpd/conf.d/ssl.conf sed -i "s#/etc/pki/tls/certs/localhost.crt#/etc/httpd/ssl/httpd.crt#g" /etc/httpd/conf.d/ssl.conf sed -i "s#/etc/pki/tls/private/localhost.key#/etc/httpd/ssl/httpd.key#g" /etc/httpd/conf.d/ssl.conf echo '配置文件修改完成' sleep 5s echo '重新启动httpd服务' systemctl restart httpd &>/dev/null ss -antl
生成https证书脚本
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
https 证书生成
https 密钥证书生成 openSSL
java https ssl 无密码 下载地址