安装依赖
sudo apt install socat
安装时可以提供邮箱地址
# 切换至 root 用户(下面使用 HTTP 验证时需要 root 权限) sudo -i # wget 默认下载到文件, 使用 '-' 表示输出到标准输出, 经管道提供给 sh 执行 wget -O - https://get.acme.sh | sh -s email=my@example.com 或者 # curl 默认下载到标准输出 curl https://get.acme.sh | sh -s email=my@example.com
安装会完成以下内容:
- 创建安装目录 ~/.acme.sh
- 创建别名 alias acme.sh=~/.acme.sh/acme.sh
- 创建一个定时任务
$ crontab -l 21 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
最后不要忘了 source ~/.bashrc, 不然别名没有生效
如果想卸载 ACME 工具, 可以执行:
acme.sh --uninstall rm -r ~/.acme.sh
签发 SSL 证书 使用 HTTP 验证
前提: 域名绑定到了当前服务器的公网 IP 地址
使用 Standalone 模式, acme.sh 自动建立服务器来完成签发, 需要临时占用 80 或 443 端口(需要 root 权限, 所以上面需要切换 root 用户)
# HTTP acme.sh --issue -d example.com --standalone -k ec-256 # 或者使用 TLS acme.sh --issue -d example.com --alpn --standalone -k ec-256
这里使用了 ec-256 秘钥, 性能比 rsa-4096 更好
可以指定多个子域名
acme.sh --issue -d example.com -d www.example.com --standalone -k ec-256
使用 DNS 手动验证
acme.sh --issue --dns -d example.com
得到以下输出:
Add the following txt record: Domain:_acme-challenge.example.com Txt value:9ihDbjYfTExAYeDs4DBUeuTo18KBzwvTEjUnSwd32-c Add the following txt record: Domain:_acme-challenge.www.example.com Txt value:9ihDbjxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Please add those txt records to the domains. Waiting for the dns to take effect.
紧接着手动添加一条 TXT 的 DNS 记录
安装证书 移动至别处
acme.sh --installcert -d example.com --fullchainpath /home/admin/example.crt --keypath /home/admin/example.key --ecc安装到 Apache/Nginx
Apache
acme.sh --install-cert -d example.com --cert-file /path/to/certfile/in/apache/cert.pem --key-file /path/to/keyfile/in/apache/key.pem --fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem --reloadcmd "service apache2 force-reload"
Nginx
acme.sh --install-cert -d example.com --key-file /path/to/keyfile/in/nginx/key.pem --fullchain-file /path/to/fullchain/nginx/cert.pem --reloadcmd "service nginx force-reload"
更新证书
默认会自动更新证书, 也可以手动强制更新证书
acme.sh --renew -d example.com --force --ecc
上文的 ec-256 属于 ECC 证书, 此处添加了 --ecc 选项



