{"id":13586554,"url":"https://github.com/jinhucheung/letscertbot","last_synced_at":"2025-04-14T16:24:12.510Z","repository":{"id":45264205,"uuid":"215936854","full_name":"jinhucheung/letscertbot","owner":"jinhucheung","description":"Let's Certbot is a tool builds automated scripts base on Certbot for obtaining, renewing, deploying SSL certificates.","archived":false,"fork":false,"pushed_at":"2020-10-06T03:58:03.000Z","size":116,"stargazers_count":148,"open_issues_count":7,"forks_count":30,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-03T04:27:16.633Z","etag":null,"topics":["acme","aliyun","certbot","certificates","deployment-automation","devops","docker","godaddy","letsencrypt","qcloud","ssl-certificates"],"latest_commit_sha":null,"homepage":"https://github.com/jinhucheung/letscertbot","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinhucheung.png","metadata":{"files":{"readme":"README-CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-18T03:49:49.000Z","updated_at":"2025-01-01T23:04:03.000Z","dependencies_parsed_at":"2022-09-24T10:00:57.264Z","dependency_job_id":null,"html_url":"https://github.com/jinhucheung/letscertbot","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinhucheung%2Fletscertbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinhucheung%2Fletscertbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinhucheung%2Fletscertbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinhucheung%2Fletscertbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinhucheung","download_url":"https://codeload.github.com/jinhucheung/letscertbot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914939,"owners_count":21182541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acme","aliyun","certbot","certificates","deployment-automation","devops","docker","godaddy","letsencrypt","qcloud","ssl-certificates"],"created_at":"2024-08-01T15:05:38.955Z","updated_at":"2025-04-14T16:24:12.477Z","avatar_url":"https://github.com/jinhucheung.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Let's Certbot\n\nLet's Certbot 是一个基于 [Certbot](https://certbot.eff.org/) 用于自动化获取、续期、部署 SSL 证书的工具。\n\n为了验证你的域名，Let's Certbot 使用了 Certbot 的 dns 方式进行验证。这对比 http 方式验证，你不需要在已部署的 Web 应用中进行任何操作，同时你也可以申请通配符证书。\n\n在 dns 验证过程中，你需要为你的域名设置一个指定内容的 TXT DNS 记录。Let's Certbot 将会通过域名服务商的 DNS API 帮助你设置。\n\n目前支持的域名服务商:\n\n- [阿里云](https://www.aliyun.com/)\n- [腾讯云](https://cloud.tencent.com/)\n- [华为云](https://www.huaweicloud.com/)\n- [GoDaddy](https://godaddy.com)\n- [Cloudflare](https://www.cloudflare.com/)\n\n## 示例\n\n![example](https://user-images.githubusercontent.com/19590194/74025460-f62e0580-49de-11ea-989d-9dccf74439d6.gif)\n\n## 安装\n\nLet's Certbot 作为一个 Certbot 工具，支持 Docker 容器或非容器方式安装。\n\n### 下载仓库\n\n首先，克隆本仓库以获取 Let's Certbot:\n\n```\n$ git clone git@github.com:jinhucheung/letscertbot.git\n```\n\n然后拷贝配置文件:\n\n```\n$ cd letscertbot\n$ cp config.json.example config.json\n```\n\n### 容器安装\n\n你可以通过 Docker 来执行 Let's Certbot:\n\n```\n$ sudo docker run --rm --name letscertbot -v \"$your_letscertbot_home/config.json:/app/config.json\" -v \"$your_letscertbot_home/tlds.txt:/app/tlds.txt\" -v \"/etc/letsencrypt:/etc/letsencrypt\" -v \"/var/lib/letsencrypt:/var/lib/letsencrypt\" jimcheung/letscertbot\n```\n\n如果你已安装 Docker Compose, 可以通过 Compose 执行:\n\n```\n$ sudo docker-compose run --rm app\n```\n\n### 非容器安装\n\nLet's Certbot 与 Certbot 执行环境一致，要求执行在类 UNIX 操作系统上且需要 Python 2.7 或 3.4+。\n\n首先，你需要确认 Python 是否已经安装:\n\n```\n$ python --version\n```\n\n如果没有问题，根据 Certbot [官方文档](https://certbot.eff.org/docs/install.html) 为你的操作系统安装 Certbot。\n\n在安装完 Certbot 后，使用 root 执行 Certbot:\n\n```\n$ sudo certbot --version\n```\n\n## 使用\n\n### 配置\n\n在执行 Let's Certbot 前，你有以下的配置需要更新:\n\n| 名称                        | 必须  | 描述                                                               | 默认                  |\n| --------------------------- | ----- | ------------------------------------------------------------------ | --------------------- |\n| base.email                  | true  | 邮箱地址，用于接收续期等通知                                       |                       |\n| dns                         | true  | dns 设置                                                           |                       |\n| dns.wait_time               | false | dns 验证等待时间(秒)                                               | 20                    |\n| dns.aliyun                  | false | 阿里云帐号的 Access Key Id 和 Access Key Secret                    |                       |\n| dns.qcloud                  | false | 腾讯云帐号的 Secret Id 和 Secret Key                               |                       |\n| dns.huaweicloud             | false | 华为云帐号的 Access Key Id 和 Secret Access Key                    |                       |\n| dns.godaddy                 | false | GoDaddy 帐号的 API Key 和 API Secret                               |                       |\n| dns.cloudflare              | false | Cloudflare 帐号的 API Key 或者 API Token                           |                       |\n| log.enable                  | false | 是否启用日志跟踪                                                   | false                 |\n| log.logfile                 | false | 日志文件路径                                                       | ./log/application.log |\n| deploy.servers              | false | 部署服务器列表                                                     |                       |\n| deploy.server.enable        | false | 部署服务器是否启用部署脚本                                         | false                 |\n| deploy.server.host          | false | 部署服务器地址，本地服务器则使用 localhost，启用部署脚本后必须提供 |                       |\n| deploy.server.port          | false | 部署远程服务器 SSH 守护进程绑定的端口                              | 22                    |\n| deploy.server.user          | false | 部署远程服务器登录的用户，用于执行部署脚本                         | root                  |\n| deploy.server.password      | false | 部署远程服务器登录的密码                                           |                       |\n| deploy.server.deploy_to     | false | 部署证书存储在服务器的路径                                         | /etc/letsencrypt/live |\n| deploy.server.restart_nginx | false | 是否在部署后重启服务器 nginx                                       | false                 |\n| deploy.server.after_hook    | false | 服务器在部署成功后执行的命令                                       |                       |\n\n此外， `tlds.txt` 文件包含了一些顶级域名(TLD)和二级域名(SLD) 用于分开域名中的子域和主域。如果你域名中的顶级域或二级域不在 `tlds.txt` 中，你需要将它添加在此文件中。\n\n### DNS API\n\n获取证书前，你可以执行 manual 脚本 (`manual.py`) 用你的 access key 测试 DNS API:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app manual --test --domain your.example.com --dns aliyun\n\n# 非容器方式\n$ sudo python ./bin/manual.py --test --domain your.example.com --dns aliyun\n```\n\n这个脚本将会通过指定的 DNS API 添加 `_acme-challenge` TXT 记录到你的域名下。\n\n### 获取证书\n\n使用 root 执行 obtainment 脚本 (`obtain.py`) 以获取证书:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app obtain -d your.example.com *.your.example.com\n\n# 非容器方式\n$ sudo python ./bin/obtain.py -d your.example.com *.your.example.com\n```\n\n然后你将在 `/etc/letsencrypt/live/` 目录下得到一个名为 `your.example.com` 通配符证书。\n\n你可以提供 `--cert` 参数指定证书名称:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app obtain -d x.example.com y.example.com --cert xny.example.com\n\n# 非容器方式\n$ sudo python ./bin/obtain.py -d x.example.com y.example.com --cert xny.example.com\n```\n\n如果你的域名提供商不支持 DNS API, 或者你担心暴露主要域名的 ACCESS TOKEN 会带来安全问题，这时候你可以使用 DNS alias 模式，如：\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app obtain -d x.main_domain.com y.main_domain.com --dns qcloud --challenge-alias alias_domain.com\n\n# 非容器方式\n$ sudo python ./bin/obtain.py -d x.main_domain.com y.main_domain.com --dns qcloud --challenge-alias alias_domain.com\n```\n\n执行上面的命令，Let's Certbot 对 `x.main_domain.com` 和 `y.main_domain.com` 域名验证转移到 `alias_domain.com` 上，并通过 `qcloud` API 为 `alias_domain.com` 域名生成验证的 TXT DNS 记录。为此你需要**提前**为待验证的域名添加 CNAME 记录，如：\n\n```\n_acme-challenge.x.main_domain.com =\u003e _acme-challenge.alias_domain.com\n_acme-challenge.y.main_domain.com =\u003e _acme-challenge.alias_domain.com\n```\n\n### 续期证书\n\n使用 renewal 脚本 (`renewal.py`) 为证书续期:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app renewal\n\n# 非容器方式\n$ sudo python ./bin/renewal.py\n```\n\nCertbot 将为所有即将到期的证书续期。\n\n你可以设置一个计划任务，将 renewal 脚本添加到 `crontab` 中:\n\n```\n# 容器方式\n0 0 */7 * * sudo docker-compose -f $your_letscertbot_home/docker-compose.yml run --rm app renewal \u003e /var/log/letscertbot-renewal.log 2\u003e\u00261\n\n# 非容器方式\n0 0 */7 * * sudo $your_letscertbot_home/bin/renewal.py \u003e /var/log/letscertbot-renewal.log 2\u003e\u00261\n```\n\n这个计划任务将每 7 天执行 renewal 脚本。\n\n如果你需要强制为指定的证书续期，可以提供 `--force` and `--certs` 参数:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app renewal --certs xny.example.com --force\n\n# 非容器方式\n$ sudo python ./bin/renewal.py --certs xny.example.com --force\n```\n\n### 部署证书\n\n如果你将 `deploy.server.enable` 设置为 true, Certbot 将执行 deployment 脚本 (`deploy.py`) 在 deploy 钩子上。这个脚本接收到已经续期的证书并将它推送到配置好的服务器中。\n\nLet's Certbot 通过 SSH 为远程服务器部署证书，这意味着你执行 Certbot 的机器须通过 SSH 连接上远程服务器。为了使连接成功，你需要**上传公钥**到远程服务器或者**提供 `deploy.server.password`** 给 `sshpass` 工具。\n\n此外，为了将证书部署到 `deploy.server.deploy_to` 或重启 nginx, Let's Certbot 要求 `deploy.server.user` 有执行对应操作的权限。\n\n你可以通过执行下面命令获取 deployment 脚本:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app deploy --check\n\n# 非容器方式\n$ sudo python ./bin/deploy.py --check\n```\n\n如果需要推送证书到配置中的服务器，可以执行:\n\n```\n# 容器方式\n$ sudo docker-compose run --rm app deploy --push --cert $certificate_name --server $server_host\n\n# 非容器方式\n$ sudo python ./bin/deploy.py --push --cert $certificate_name --server $server_host\n```\n\n**Note**: 如果 `deploy.server` 以强制模式启动了 SELinux, 你需要确认 nginx 有权限访问 `deploy.server.deploy_to` 的 SELinux 安全上下文。\n\n**Note**: 如果你以容器方式运行 Let's Certbot，同时需要在部署证书后重启本地 nginx 服务，则应该使用远程服务器方式配置本地服务器。\n\n## 致谢\n\n- [Certbot](https://github.com/certbot/certbot)\n- [letsencrypt-aliyun-dns-manual-hook](https://github.com/broly8/letsencrypt-aliyun-dns-manual-hook)\n- [certbot-letencrypt-wildcardcertificates-alydns-au](https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au)\n\n## 贡献\n\n欢迎报告 Bug 或提交 Pull Request。\n\n1. 分叉此仓库\n2. 创建你的功能分支 (git checkout -b my-new-feature)\n3. 提交你的改动 (git commit -am 'Add some feature')\n4. 推送到当前分支 (git push origin my-new-feature)\n\n如有必要，请为你的代码编写单元测试。\n\n## 许可\n\n根据 [MIT](MIT-LICENSE) 许可的条款，此仓库可作为开放源代码使用。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinhucheung%2Fletscertbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinhucheung%2Fletscertbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinhucheung%2Fletscertbot/lists"}