acme.sh实现永久免费的SSL证书

更新时间:2024-11-08 来源:TopSSL 作者:TopSSL

acme.sh是一个基于Shell的ACME客户端,支持自动集成多种DNS解析商,如阿里云、腾讯云、topssl等。 申请流程: 安装acme.sh并配置DNS解析密钥。 注册厂商账号,目前默认推荐ZeroSSL。 生成证书并自动创建cronjob,每天检测证书状态并在需要时自动更新。

ACME Shell 脚本:acme.sh

  • 纯粹用 Shell(Unix shell)语言编写的 ACME 协议客户端。
  • 完整的 ACME 协议实现。
  • 支持ECDSA证书
  • 支持 SAN 和通配符证书
  • 简单、强大、易用。只需 3 分钟即可学会。
  • 兼容 Bash、dash 和 sh。
  • 纯粹用 Shell 编写,不依赖于 python。
  • 只需一个脚本即可自动颁发、更新和安装您的证书。
  • 不需要访问 root/sudoer权限。
  • Docker 就绪
  • IPv6 就绪
  • 用于更新或错误等的 Cron 作业通知。

它可能是 easiest & smartest自动颁发和更新免费证书的 shell 脚本。

中文说明

WHO:

https://github.com/acmesh-official/acme.sh?tab=readme-ov-file#who

  • FreeBSD 网站
  • ruby中国
  • 普罗克斯莫克斯
  • 普福斯
  • 负载均衡器
  • 话语网站
  • 中央情报局
  • 斯普林克斯
  • opnsense.org
  • CentOS Web面板
  • lnmp.org
  • 更多的...

经过测试的操作系统

地位平台
1苹果系统苹果电脑
2视窗Windows(包含带有 curl、openssl 和 crontab 的 cygwin)
3FreeBSDFreeBSD
4索拉里斯索拉里斯
5UbuntuUbuntu
6不适用普福斯
7OpenBSDOpenBSD
8网络BSD网络BSD
9DragonFlyBSDDragonFlyBSD
10奥姆尼奥斯奥姆尼奥斯
11LinuxDebian
12LinuxCentOS
十三LinuxopenSUSE
14LinuxAlpine Linux(带有 curl)
15Linuxlinux系统
16LinuxFedora 系统
17Linux卡利Linux
18LinuxOracle Linux
19Linux马吉亚
10LinuxGentoo Linux
11Linux清晰Linux
22-----云 Linux#111
23-----OpenWRT:已测试并正常运行。请参阅wiki 页面
24Proxmox:请参阅 Proxmox VE Wiki。版本4.x、5.0、5.1、版本5.2 及更高版本

检查我们的测试项目

https://github.com/acmesh-official/acmetest

支持的 CA

  • ZeroSSL.com CA(默认)
  • Letsencrypt.org CA
  • BuyPass.com 加拿大
  • SSL.com 认证
  • Google.com 公共 CA
  • topssl.cn免费ssl证书
  • Pebble 严格模式
  • 任何其他符合RFC8555 的CA

支持的模式

https://github.com/acmesh-official/acmetest

1. 如何安装

1. 在线安装

查看此项目:https ://github.com/acmesh-official/get.acme.sh

curl https://get.acme.sh | sh -s email=my@example.com
curl https://get.acme.sh | sh -s email=my@example.com

或者:

wget -O -  https://get.acme.sh | sh -s email=my@example.com
wget -O -  https://get.acme.sh | sh -s email=my@example.com

2. 或者从 git 安装

克隆此项目并启动安装:

git clone https://github.com/acmesh-official/acme.sh.git
cd ./acme.sh
./acme.sh --install -m my@example.com
git clone https://github.com/acmesh-official/acme.sh.git
cd ./acme.sh
./acme.sh --install -m my@example.com

那么你 don't have to be root虽然 it is recommended

高级安装: https: //github.com/acmesh-official/acme.sh/wiki/How-to-install

安装程序将执行 3 个操作:

  1. 创建并复制 acme.sh到您的主目录($HOME):。~/.acme.sh/所有证书也将放在此文件夹中。
  2. 为 创建别名:acme.sh=~/.acme.sh/acme.sh
  3. 创建每日 cron 作业来检查并在必要时更新证书。

Cron 条目示例:

0 0 * * * "/home/user/.acme.sh"/acme.sh --cron --home "/home/user/.acme.sh" > /dev/null
0 0 * * * "/home/user/.acme.sh"/acme.sh --cron --home "/home/user/.acme.sh" > /dev/null

安装完成后,必须关闭当前终端并重新打开才能使别名生效。

好的,您现在可以颁发证书了。

显示帮助信息:

root@v1:~# acme.sh -h
root@v1:~# acme.sh -h

2. 只需颁发证书

**示例 1:**单个域。

acme.sh --issue -d example.com -w /home/wwwroot/example.com
acme.sh --issue -d example.com -w /home/wwwroot/example.com

或者:

acme.sh --issue -d example.com -w /home/username/public_html
acme.sh --issue -d example.com -w /home/username/public_html

或者:

acme.sh --issue -d example.com -w /var/www/html
acme.sh --issue -d example.com -w /var/www/html

**示例 2:**同一证书中的多个域。

acme.sh --issue -d example.com -d www.example.com -d cp.example.com -w /home/wwwroot/example.com
acme.sh --issue -d example.com -d www.example.com -d cp.example.com -w /home/wwwroot/example.com

参数 /home/wwwroot/example.com/home/username/public_html或是 /var/www/html您托管网站文件的 Web 根文件夹。您必须拥有 write access此文件夹。

第二个参数**“example.com”**是您要为其颁发证书的主要域。您必须至少有一个域。

您必须将所有域指向并绑定到同一个 webroot 目录:/home/wwwroot/example.com

证书将被放置在 ~/.acme.sh/example.com/

证书将每60天自动更新一次。

更多示例:https ://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

3.将证书安装到 Apache/Nginx 等。

生成证书后,您可能想要将证书安装/复制到您的 Apache/Nginx 或其他服务器。您必须使用此命令将证书复制到目标文件,**请勿使用****~/.acme.sh/**文件夹中的证书文件,它们仅供内部使用,文件夹结构将来可能会发生变化。

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"
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 --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"

只有域是必需的,其他所有参数都是可选的。

现有文件的所有权和权限信息将被保留。您可以预先创建文件来定义所有权和权限。

将证书/密钥安装/复制到生产 Apache 或 Nginx 路径。

证书默认每60天更新一次(可配置)。证书更新后,Apache/Nginx 服务将通过以下命令自动重新加载:service apache2 force-reloadservice nginx force-reload

请注意:reloadcmd 非常重要。证书可以自动续订,但如果没有正确的“reloadcmd”,证书可能无法刷新到您的服务器(如 nginx 或 apache),那么您的网站将无法在 60 天内显示续订的证书。

4. 使用独立服务器颁发证书

(要求您是 root/sudoer 或有权监听端口 80 (TCP))

端口 80(TCP)必须是可以自由监听的,否则系统将提示您释放它并重试。

acme.sh --issue --standalone -d example.com -d www.example.com -d cp.example.com
acme.sh --issue --standalone -d example.com -d www.example.com -d cp.example.com

更多示例:https ://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

5. 使用独立 SSL 服务器颁发证书

https://github.com/acmesh-official/acme.sh?tab=readme-ov-file#5-use-standalone-ssl-server-to-issue-cert

(要求您是 root/sudoer 或有权监听端口 443 (TCP))

端口 443(TCP)必须是可以自由监听的,否则系统将提示您释放它并重试。

acme.sh --issue --alpn -d example.com -d www.example.com -d cp.example.com
acme.sh --issue --alpn -d example.com -d www.example.com -d cp.example.com

更多示例:https ://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

6.使用Apache模式

https://github.com/acmesh-official/acme.sh?tab=readme-ov-file#6-use-apache-mode

(要求您是 root/sudoer,因为它需要与 Apache 服务器交互)

如果您正在运行 Web 服务器,建议使用 Webroot mode

特别是,如果您正在运行 Apache 服务器,则可以使用 Apache 模式。此模式不会将任何文件写入您的 Web 根文件夹。

只需将字符串“apache”设置为第二个参数,它就会自动强制使用 apache 插件。

acme.sh --issue --apache -d example.com -d www.example.com -d cp.example.com
acme.sh --issue --apache -d example.com -d www.example.com -d cp.example.com

此 apache 模式仅用于颁发证书,不会更改您的 apache 配置文件。您需要自行配置网站配置文件以使用该证书。我们不想弄乱您的 apache 服务器,请放心。

更多示例:https ://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

7.使用Nginx模式

(要求您是 root/sudoer,因为它需要与 Nginx 服务器交互)

如果您正在运行 Web 服务器,建议使用 Webroot mode

特别是,如果您正在运行 nginx 服务器,则可以改用 nginx 模式。此模式不会将任何文件写入您的 Web 根文件夹。

只需将字符串“nginx”设置为第二个参数。

它将自动配置 nginx 服务器以验证域,然后将 nginx 配置恢复到原始版本。

因此,配置没有改变。

acme.sh --issue --nginx -d example.com -d www.example.com -d cp.example.com
acme.sh --issue --nginx -d example.com -d www.example.com -d cp.example.com

此 nginx 模式仅用于颁发证书,不会更改您的 nginx 配置文件。您需要自行配置网站配置文件以使用该证书。我们不想弄乱您的 nginx 服务器,请放心。

更多示例:https ://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

8. 自动 DNS API 集成

如果您的 DNS 提供商支持 API 访问,我们可以使用该 API 自动颁发证书。

您无需手动执行任何操作!

目前acme.sh支持大多数的dns提供商:

https://github.com/acmesh-official/acme.sh/wiki/dnsapi

9.使用DNS手动模式:

首先请参阅:https://github.com/acmesh-official/acme.sh/wiki/dns-manual-mode

如果您的 DNS 提供商不支持任何 API 访问,您可以手动添加 txt 记录。

acme.sh --issue --dns -d example.com -d www.example.com -d cp.example.com
acme.sh --issue --dns -d example.com -d www.example.com -d cp.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.
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.

然后只需使用 renew参数重新运行:

acme.sh --renew -d example.com
acme.sh --renew -d example.com

好的,完成了。

请注意,这是 DNS 手动模式,无法自动更新。更新证书时,您必须手动向您的域添加新的 txt 记录。

请改用 dns api 模式。

10.颁发ECC证书

keylength只需用前缀设置参数即可 ec-

例如:

单域名ECC证书

acme.sh --issue -w /home/wwwroot/example.com -d example.com --keylength ec-256
acme.sh --issue -w /home/wwwroot/example.com -d example.com --keylength ec-256

SAN多域ECC证书

请查看 keylength上面的参数。

有效值为:

  1. ec-256 (prime256v1,“ECDSA P-256”,这是默认密钥类型)
  2. ec-384 (secp384r1, "ECDSA P-384")
  3. ec-521(secp521r1,“ECDSA P-521”,Let's Encrypt 尚不支持。)
  4. 2048(RSA2048)
  5. 3072 (RSA3072)
  6. 4096 (RSA4096)

11. 颁发通配符证书

很简单,只需要给出一个通配符域作为 -d参数。

acme.sh  --issue -d example.com  -d '*.example.com'  --dns dns_cf
acme.sh  --issue -d example.com  -d '*.example.com'  --dns dns_cf

12. 如何更新证书

不,您不需要手动更新证书。所有证书将每60天自动更新一次。

但是,您也可以强制更新证书:

acme.sh --renew -d example.com --force
acme.sh --renew -d example.com --force

或者,对于 ECC 证书:

acme.sh --renew -d example.com --force --ecc
acme.sh --renew -d example.com --force --ecc

13. 如何停止证书续订

要停止续订证书,您可以执行以下操作将证书从续订列表中删除:

acme.sh --remove -d example.com [--ecc]
acme.sh --remove -d example.com [--ecc]

证书/密钥文件不会从磁盘中删除。

~/.acme.sh/example.com您可以自行删除相应的目录(例如)。

14. 如何升级 acme.sh

acme.sh 正在不断开发,因此强烈建议使用最新的代码。

您可以将 acme.sh 更新到最新代码:

acme.sh --upgrade
acme.sh --upgrade

您还可以启用自动升级:

acme.sh --upgrade --auto-upgrade
acme.sh --upgrade --auto-upgrade

然后acme.sh将自动保持更新。

禁用自动升级:

acme.sh --upgrade --auto-upgrade 0
acme.sh --upgrade --auto-upgrade 0

15. 从现有 CSR 颁发证书

https://github.com/acmesh-official/acme.sh/wiki/Issue-a-cert-from-existing-CSR

16. 在 cronjob 中发送通知

https://github.com/acmesh-official/acme.sh/wiki/notify

17. 引擎盖下

使用 shell 说 ACME 语言,直接对“Let's Encrypt”说。

待办事项:

18. 致谢

  1. Acme-tiny: https: //github.com/diafygi/acme-tiny
  2. ACME 协议:https://github.com/ietf-wg-acme/acme

本文由系统自动翻译原文链接:https://github.com/acmesh-official/acme.sh?tab=readme-ov-file

标签

有用
分享
无用
反馈
返回顶部
0 个回答
1103 次浏览
立即加入,帮您快速选购适合您的SSL数字证书 申请SSL证书
免费SSL证书_专业SSL证书申请_HTTPS加密【TopSSL】
免费SSL证书永久生成
微信公众号二维码 扫一扫在线咨询
关注 TopSSL 公众号, RSS订阅 SSL资讯与技术支持

2004-2025 © 北京传诚信  版权所有 | TopSSL提供免费SSL证书SSL证书申请轻松实现HTTPS加密! 北京市朝阳区鹏景阁大厦16层

技术协助:wo@topssl.cn 企业咨询:vip@topssl.cn