将替代名称添加到 letsencrypt 证书的自动方法

Automated way to add a alternative name to a letsencrypt Cert

我正在寻找一种自动添加新域的方法。

我要加erzgebirgstraverse.de

来自 https://certbot.eff.org/docs/using.html#changing-a-certificate-s-domains :

... to expand the set of domains a certificate contains ...

certbot certonly --cert-name example.com -d example.org,www.example.org

我找到了一种列出所有现有证书的方法:

hz1:/etc/apache2# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: hz1.yz.to
    Serial Number: 345a3c36ff032d325e78120c98d8ddc71f7
    Domains: hz1.yz.to thomas-guettler.de
    Expiry Date: 2021-03-23 09:19:00+00:00 (VALID: 80 days)
    Certificate Path: /etc/letsencrypt/live/hz1.yz.to/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/hz1.yz.to/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

现在我看到了现有域,并且可以使用 -d 标志添加 erzgebirgstraverse.de

hz1:/etc/apache2# certbot certonly --cert-name hz1.yz.to -d hz1.yz.to,thomas-guettler.de,erzgebirgstraverse.de

但是现在交互式脚本开始了:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Apache Web Server plugin (apache)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 
systemctl reload apache2

有没有办法添加新域(替代名称)但非交互式

默认情况下,Certbot 会尝试协助您生成证书。此外,它会提示您提供信息以帮助您在 Apache/Nginx 设置中安装它们。

要跳过此安装步骤,只需使用 certbot certonly ... 子命令。根据the CLI manpagesObtain or renew a certificate, but do not install it

或者,您可以使用标志 -n/--non-interactive 来确保 certbot 将在不提示任何情况下进行处理。在这种情况下,您必须确保所有需要的信息都通过命令行传递。特别是,您必须确保您已同意条款和条件 (--agree-tos) 并且您提供了有效的联系电子邮件 (-m email@domain)。示例:

certbot certonly --agree-tos -m contact&mydomain.com --cert-name hz1.yz.to -d hz1.yz.to,thomas-guettler.de,erzgebirgstraverse.de

在您的问题中,系统提示您输入身份验证方法。您必须了解,let's encrypt 必须验证您正在执行的服务器,客户端可以正确地与您尝试生成证书的域相关联。可用的方法是:

  1. Apache Web 服务器插件 (apache) -> certbot 将创建 apache 设置,以便 HTTP 质询可用于验证域是否实际与您的服务器相关联
  2. 启动临时网络服务器(独立)-> Certbot 将 运行 它自己的网络服务器来执行 HTTP 质询。这只有在没有其他网络服务器在端口 80 上侦听时才有效(apache 和 nginx 将在该地址上侦听)。这种方法在大多数服务器中可能没用
  3. 将文件放在 webroot 目录 (webroot) -> 如果你已经有一个 HTTP 服务器侦听端口 80,你可以指示 certbot 将文件放在 webroot 目录中,以便可以使用 HTTP challenge。

要从命令行预 select 3 种可用方法之一(并避免交互式提示),请使用选项 --apache (1)、--standalone (2) 或--webroot (3).

请记住,HTTP 质询并不是验证 server/domains 一致性的唯一解决方案。基于 DNS 和 TLS 的挑战可能非常有用:https://letsencrypt.org/docs/challenge-types/ 我不确定 certbot 是否会在本机实现此类挑战,但您可以找到第三方插件。

此外,认为 certbot 不是唯一可用于生成证书的 let's encrypt 客户端。有很多可用的客户:https://letsencrypt.org/docs/client-options/

您至少需要:--non-interactive--agree-tos-m 'you@your-email.com'。这将允许 certbot 运行 无需任何交互。

此外,如果适合您的配置,指定 --nginx--apache 可能会有用(未指定这是什么网络服务器类型),或者 certonly --manual 如果你实际上只需要证书。

一个完成命令的例子来完成你正在寻找的东西(假设这里是 nginx)是:certbot --nginx --non-interactive --agree-tos -m 'you@your-email.com' -d 'erzgebirgstraverse.de'

请注意,所有这些都在 https://certbot.eff.org/docs/using.html

中指定(以某种迂回的方式)