# Certbot

**Certbot** 是一款免费、开源的命令行工具，由[电子前沿基金会](https://www.edgepedia.org/zh/electronic-frontier-foundation)（EFF）维护，它使用 ACME 协议从证书颁发机构获取 TLS/SSL 证书，并能自动在 Web 服务器上安装和续期这些证书。<sup>[1](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)</sup> 它是为 [Let's Encrypt](https://www.edgepedia.org/zh/lets-encrypt) 而编写的——这个免费的证书颁发机构由 EFF、Mozilla 等机构共同发起——并能将它获取的证书直接部署到 Web 服务器上。<sup>[2](https://github.com/certbot/certbot/blob/main/certbot/README.rst)</sup> Let's Encrypt 建议大多数人从 Certbot 入手，称其易于使用、可在多种操作系统上运行，且文档完善。<sup>[3](https://letsencrypt.org/docs/client-options/)</sup>

| 关键事实 | 详情 |
|---|---|
| 维护者 | 电子前沿基金会（EFF）；最初随 Let's Encrypt 的发布而创建<sup>[1](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)</sup><sup> • </sup><sup>[4](https://jhalderm.com/pub/papers/letsencrypt-ccs19.pdf)</sup> |
| 首次发布 | 2016 年春季，作为一款使用 Let's Encrypt 证书自动启用 HTTPS 的命令行工具<sup>[5](https://www.eff.org/wp/certbot-usability-case-study-making-it-easier-get-https-certificates)</sup> |
| 实现 | Python 3；在现代 Linux 发行版上推荐通过 Snap 包安装<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[7](https://github.com/certbot/certbot/blob/main/certbot/docs/install.rst)</sup> |
| 质询方式 | HTTP-01（80 端口）和 DNS-01（DNS TXT 记录）；通配符证书只能通过 DNS-01 获得<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup> |
| Web 服务器集成 | Apache 和 NGINX 插件可自动安装证书并配置服务器<sup>[1](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)</sup> |
| 续期 | 通过 systemd 定时器（Snap 安装）或 cron 自动完成；钩子可在续期之前、之后以及续期证书成功部署时运行命令<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup> |
| 当前版本 | Certbot 5.8.0，发布于 2026 年 9 月 1 日；需要 cryptography 47.0.0 或更高版本<sup>[9](https://github.com/certbot/certbot/releases/)</sup> |

## 起源

该客户端最初是 Let's Encrypt 的官方客户端，用 Python 编写。2016 年，项目更名为 Certbot，其开发工作由 EFF 接管——EFF 正是随 Let's Encrypt 的发布而创建了该客户端。<sup>[10](https://community.letsencrypt.org/t/new-name-certbot-for-python-lets-encrypt-client/15688)</sup><sup> • </sup><sup>[4](https://jhalderm.com/pub/papers/letsencrypt-ccs19.pdf)</sup> EFF 将 Certbot 描述为其“加密整个互联网”努力的一部分：Web 服务器通过受信任的证书颁发机构签发的证书向浏览器证明自己的身份，而 Certbot 则自动化地从 Let's Encrypt 获取并部署这些证书。<sup>[2](https://github.com/certbot/certbot/blob/main/certbot/README.rst)</sup>

## 工作原理

Certbot 实现了自动化证书管理环境（ACME）协议，即 RFC 8555——Let's Encrypt 用该协议在签发证书前验证申请者是否控制某个域名。<sup>[3](https://letsencrypt.org/docs/client-options/)</sup> 为证明域名控制权，客户端需要完成一项质询。Certbot 支持两种主要类型：<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup>

- **HTTP-01**：客户端将令牌文件放置在 Web 服务器上一个约定的 URL 下，即 Web 根目录中的 `/.well-known/acme-challenge/`，证书颁发机构通过 80 端口获取该文件。这适用于普通的单域名证书，但无法签发通配符证书。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup><sup> • </sup><sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup>
- **DNS-01**：客户端在域名的 DNS 区域中添加一条 [TXT 记录](https://www.edgepedia.org/zh/txt-record)，因此验证通过 DNS 而非 HTTP 进行。这是唯一支持 `*.example.com` 这类通配符证书的方法。<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup>

通配符证书覆盖域名下的任意单级标签，因此 `*.example.com` 对 `www.example.com` 和 `mail.example.com` 有效，但对 `example.com` 本身或 `hello.goodbye.example.com` 这类深两级的名称无效。<sup>[11](https://certbot.eff.org/)</sup>

**插件。** Certbot 通过插件将认证与安装分离。认证插件完成质询；安装插件部署生成的证书。在受支持的系统上，Apache 和 NGINX 插件将签发和续期与 Web 服务器集成，编辑其配置并重新加载服务。<sup>[1](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)</sup> `webroot` 模式将质询文件放入现有站点的目录中，`standalone` 模式运行自带的临时 Web 服务器，而 `manual` 插件允许操作员手动执行验证步骤，包括从目标 Web 服务器以外的机器上执行。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup> DNS-01 自动化由针对各服务商的独立 DNS 插件提供，例如适用于 Amazon Route 53 的 certbot-dns-route53。<sup>[7](https://github.com/certbot/certbot/blob/main/certbot/docs/install.rst)</sup>

## 续期与钩子

Let's Encrypt 签发的证书有效期很短，因此续期是该工具的核心功能。在现代 Linux 发行版上通过 Snap 安装 Certbot 时，systemd 定时器会自动运行续期，无需配置 cron；在其他环境中则会添加一个调用 `certbot renew` 的 cron 任务，该命令可以安全地频繁运行，因为只有在证书临近到期时才会真正续期。<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup>

**钩子**让操作员在每次续期前后运行命令。`--pre-hook` 和 `--post-hook` 在每次续期尝试之前和之后运行，例如用于停止和重启 Web 服务器，以便 standalone 插件能够绑定所需端口。`--deploy-hook` 仅在证书实际续期后运行，这一点很重要，因为无论续期成功还是无需续期，`certbot renew` 都会以状态码 0 退出。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup> 放置在 `/etc/letsencrypt/renewal-hooks/pre`、`deploy` 和 `post` 目录中的可执行文件会按字母顺序自动运行；自 Certbot 3.2.0 起，这些目录钩子对任何子命令都会运行，而不仅限于 `renew`。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup> 自 Certbot 2.7.0 起，续期后钩子会收到 `RENEWED_DOMAINS` 和 `FAILED_DOMAINS` 环境变量，即以空格分隔的域名列表，让脚本能够检测续期是否成功。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup>

一种常见的运维故障模式是：续期成功了，但 Web 服务仍在从内存中提供旧证书；文档记载的补救方法是使用部署钩子重新加载服务器，并用 `certbot renew --dry-run` 针对预发布端点测试配置。<sup>[8](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)</sup>

## 安装

推荐的安装方式是 Snap 包，适用于使用 systemd 的发行版上的 x86_64、ARMv7 和 ARMv8 架构。该 Snap 包提供最新版本，预配置了自动续期，并通过 Snap 守护进程应用更新。其他选择包括 Docker 镜像（无法将证书安装到主机上的 Web 服务器中，因为安装插件无法从容器内部访问它）、pip 以及第三方发行版的软件包。已弃用的 `certbot-auto` shell 脚本不再受支持。<sup>[7](https://github.com/certbot/certbot/blob/main/certbot/docs/install.rst)</sup> Certbot 可在 Linux、macOS、BSD 和 Windows 上运行，在拥有 root 或管理员权限时最为有用，因为这样可以自动配置 Apache 和 NGINX 的 TLS。<sup>[7](https://github.com/certbot/certbot/blob/main/certbot/docs/install.rst)</sup>

## Certbot 与其他 ACME 客户端的比较

Let's Encrypt 列出了数十种用多种语言编写的第三方 ACME 客户端，在 ACMEv1 支持于 2021 年 6 月被逐步淘汰后，它们都支持 RFC 8555 的 ACMEv2 API。<sup>[3](https://letsencrypt.org/docs/client-options/)</sup> 最常见的比较对象是 **acme.sh**，一个纯 POSIX shell 脚本客户端。<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup>

| 特性 | Certbot | acme.sh |
|---|---|---|
| 语言 | Python 3 | 纯 shell（bash/dash/sh） |
| 需要 root | 默认需要 | 不需要，可以以任意用户身份运行 |
| Web 服务器自动配置 | Apache 和 NGINX 插件 | 手动，通过 `--reloadcmd` 钩子 |
| DNS 服务商 | 约 50 个 DNS 插件 | 150 多个内置 DNS API 钩子 |
| TLS-ALPN-01 验证 | 不支持 | 支持 |
| 续期调度器 | systemd 定时器（Snap）或 cron | 安装时设置 cron 任务 |
| 多 CA 支持 | Let's Encrypt、ZeroSSL | Let's Encrypt、ZeroSSL、Google、BuyPass、SSL.com 等 |

比较表来源：<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[12](https://staging.encryptionconsulting.com/acme-clients-linux-ssl-tls-management/)</sup>

实际的区别在于适用性而非质量：对于运行 Apache 或 NGINX 的标准 Linux Web 服务器，Certbot 是更简单的选择，其插件可以配置一切；而 acme.sh 适合受限环境、脚本化流水线，以及需要广泛 DNS API 覆盖或非特权运行的场景。<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[12](https://staging.encryptionconsulting.com/acme-clients-linux-ssl-tls-management/)</sup> Certbot 的项目维护者拒绝添加 TLS-ALPN-01 支持，引导无法使用 HTTP-01 的用户改用 DNS-01，并推荐 Caddy 和 Traefik 等服务器，或 acme.sh，以获得原生 TLS-ALPN-01 支持。<sup>[13](https://github.com/certbot/certbot/wiki/Architectural-Decision-Records-2025)</sup> 对于 Windows 和 IIS，典型的客户端是 win-acme 和 Posh-ACME 而非 Certbot，后者的官方支持主要集中在主流 Linux 和 BSD 变体上。<sup>[1](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)</sup>

## 采用情况

2019 年一项关于 Let's Encrypt 早期部署的学术研究直接衡量了 Certbot 的覆盖面：在研究期间，按唯一 IP 地址统计的 ACME 客户端中有 50% 使用 Certbot，约 16% 的证书是通过它申请的。<sup>[4](https://jhalderm.com/pub/papers/letsencrypt-ccs19.pdf)</sup> 它的社区足迹依然庞大，这得益于 EFF 的官方文档、第一方 Apache 和 NGINX 插件，以及它作为 Let's Encrypt 自身指南中指定客户端的地位。<sup>[6](https://sslinsights.com/certbot-vs-acme-sh/)</sup><sup> • </sup><sup>[3](https://letsencrypt.org/docs/client-options/)</sup>

## References

1. [Which ACME Client Should I Choose? DigiCert](https://www.digicert.com/articles/acme/which-acme-client-should-i-choose)
2. [certbot/certbot README.rst, GitHub](https://github.com/certbot/certbot/blob/main/certbot/README.rst)
3. [ACME Client Implementations, Let's Encrypt](https://letsencrypt.org/docs/client-options/)
4. [Let's Encrypt: An Automated Certificate Authority to Encrypt the Entire Web (CCS 2019)](https://jhalderm.com/pub/papers/letsencrypt-ccs19.pdf)
5. [Certbot Usability Case Study, EFF](https://www.eff.org/wp/certbot-usability-case-study-making-it-easier-get-https-certificates)
6. [Certbot vs acme.sh: Which ACME Client Should You Use in 2026? SSL Insights](https://sslinsights.com/certbot-vs-acme-sh/)
7. [certbot/certbot docs/install.rst, GitHub](https://github.com/certbot/certbot/blob/main/certbot/docs/install.rst)
8. [certbot/certbot docs/using.rst, GitHub](https://github.com/certbot/certbot/blob/main/certbot/docs/using.rst)
9. [Releases, certbot/certbot, GitHub](https://github.com/certbot/certbot/releases/)
10. [New name (Certbot) for Python Let's Encrypt client, Let's Encrypt Community](https://community.letsencrypt.org/t/new-name-certbot-for-python-lets-encrypt-client/15688)
11. [Certbot homepage and glossary, EFF](https://certbot.eff.org/)
12. [ACME Clients on Linux: 5 Tools for Easy SSL/TLS Management, Encryption Consulting](https://staging.encryptionconsulting.com/acme-clients-linux-ssl-tls-management/)
13. [Architectural Decision Records 2025, certbot/certbot Wiki](https://github.com/certbot/certbot/wiki/Architectural-Decision-Records-2025)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Network defense and threats › TLS and transport-layer security

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/certbot

English original: https://www.edgepedia.org/certbot
