233 字
1 分钟
zerossl获取一年免费泛证书
环境配置:
本脚本推荐使用centos stream 8 ,在使用本脚本前,请先更新源,并且安装wget这个插件
开始教程
首先去zerossl官网注册一个账号Dashboard - ZeroSSL(这个邮箱可以随便填,不会验证)
新建脚本文件zerossl.sh
将账号密码替换以下User_Name,User_Pawd字段
#!/bin/bash# ZeroSSL 证书申请脚本# 作者: null
# 用户邮箱User_Name='邮箱'# 用户密码User_Pawd='密码'# 密码编码User_Pawd_E=$(echo -n "${User_Pawd}"|sha256sum |awk '{print $1}')
# 登录信息Login_Info=`curl -v -X POST -c cookie.db -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d "postArray={\"email_address\":\"${User_Name}\",\"password\":\"${User_Pawd_E}\"}" 'https://app.zerossl.com/ajax/public_ajax_handler.php?type=sign_in' 2>&1`
if [[ "${Login_Info}" =~ 'success":1,' ]];then echo "用户 ${User_Name} 登录成功."else echo "用户 ${User_Name} 登录失败." exit 1fi
# CookieLogin_Cpt=`echo "${Login_Info}"|awk -F'[ :=;]+' '/Set-Cookie:[[:space:]]_cpt/ {print $4}'`
User_Login_Cookie(){ curl -s -b cookie.db -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' "${@}"}
Login_Auth=`User_Login_Cookie 'https://app.zerossl.com/dashboard'`if [ -z "${Login_Auth}" ];then echo "$User_Name 未登录." exit 1fi
# 密钥目录SSL_Key_Dir='ssl_key'# 检查目录是否存在if [ ! -d "${SSL_Key_Dir}" ];then mkdir "${SSL_Key_Dir}"fi
if [ -z "${1}" ];then read -ep '请输入域名:' Gen_Domainelse Gen_Domain="${1}"fi
# 订阅Subscription_Plan=`User_Login_Cookie -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d 'postArray={"plan_id":"512","payment_frequency":"monthly"}' "https://app.zerossl.com/ajax/advanced_ajax_handler.php?type=change_subscription_plan&_cpt=${Login_Cpt}"`if [[ "${Subscription_Plan}" =~ 'success":1,' ]];then echo "用户 ${User_Name} 订阅成功."else echo "用户 ${User_Name} 订阅失败." exit 1fi
# 降级订阅Downgrade_Plan=`User_Login_Cookie -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -d 'postArray={"plan_id":"477","payment_frequency":"monthly"}' "https://app.zerossl.com/ajax/advanced_ajax_handler.php?type=change_subscription_plan&_cpt=${Login_Cpt}"`
# ZeroSSL API 密钥User_Token=`User_Login_Cookie 'https://app.zerossl.com/developer' |grep -A 1 '"access_key"'|awk -F'[ ><]+' '/span/ {print $3}'`if [ -z "${User_Token}" ];then echo "用户密钥为空" exit 1fi
Gen_Domain_D=$(echo "${Gen_Domain}"|sed -r 's/\*\./_/g;s/\./_/g')echo "域名信息: ${Gen_Domain} ${Gen_Domain_D}"Domain_Key_Path="${SSL_Key_Dir}/${Gen_Domain_D}.key"Domain_Csr_Path="${SSL_Key_Dir}/${Gen_Domain_D}_csr.pem"if [ ! -f "${Domain_Key_Path}" ];then openssl genrsa -out "${Domain_Key_Path}" 2048fi
if [ ! -f "${Domain_Csr_Path}" ];then openssl req -new -key ${Domain_Key_Path} -out ${Domain_Csr_Path} -subj "/C=CN/CN=${Gen_Domain}"fi
# 格式化Domain_Csr_Code=$(cat "${Domain_Csr_Path}" | tr -d '\n')Post_Cert_Code=$(curl -s -X POST -H 'Content-Type: application/json' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' -d "{\"certificate_domains\": \"${Gen_Domain}\", \"certificate_validity_days\": 365, \"certificate_csr\": \"${Domain_Csr_Code}\", \"strict_domains\": 1}" "http://api.zerossl.com/certificates?access_key=${User_Token}")
if [[ "${Post_Cert_Code}" =~ 'success' ]];then echo "订单失败: ${Post_Cert_Code}"else echo "订单成功: ${Post_Cert_Code}"fi使用sh zerossl.sh运行脚本
随后输入泛域名列如*.xxx.com,普通域名可以直接使用xxx.com,1.xxx.com

此时代表申请成功,我们进入zerossl官网后台,点击进入Draft ---> verify进入配置


配置dns

将cname值解析到域名内,这里以腾讯云为例

回到zerossl后台,点击Verify Domains验证dns
验证完成后就可以下载pem,cre文件,这时候并没有key,我们回到脚本位置的ssl_sky目录内就可以看到了

然后将key下载到本地,配置

分享
如果这篇文章对你有帮助,欢迎分享给更多人!
zerossl获取一年免费泛证书
https://6wd.cn/posts/zerossl-free-wildcard-cert/ 部分信息可能已经过时
相关文章 智能推荐
1
系统镜像站
实用教程 CentOS下载时版本选择:
2
防火墙常用命令
学习笔记 systemctl status firewalld.service
3
CentOS 7 内核升级脚本 (kernel-lt-5.4)
学习笔记 set -eo pipefail
4
Alist S3 上传指定目录脚本文档
实用教程 此文档将指导你如何使用修改后的 Python 脚本,其中包括以下功能:
5
Ubuntu获取root权限
学习笔记 $是普通管员,#是系统管理员,在Ubuntu下,root用户默认是没有密码的,因此也就无法使用(据说是为了安全)。想用root的话,得给root用户设置一个密码:





