分類
SSL 最新文章

Certbot 自動續約,自動驗證 DNS 域名所有權 – LiveDNS

因為自己在使用 Let’s Encrypt 的憑證,所以也有使用 Certbot 這個機器人來幫我簽署免費憑證,它可以使用 DNS 的方式來驗證,因為我使用的是 Gandi LiveDNS,內建不支援,只好自己來寫一個 DNS 的 Plugin。

因為自己在使用 Let’s Encrypt 的憑證,所以也有使用 Certbot 這個機器人來幫我簽署免費憑證,它可以使用 DNS 的方式來驗證,因為我使用的是 Gandi LiveDNS,內建不支援,只好自己來寫一個 DNS 的 Plugin。

Certbot

Certbot

Certbot 是基於 Let’s Encrypt 的服務,能夠在像是 Linux 系統上使用命令列的模式自動申請憑證或是續約憑證。

由於 Let’s Encrypt 的憑證只有 90 天的有效期,所以每隔 90 天就必須手動續約一次,很麻煩,所以就有人寫了程式可以自動申請與續約。

因為申請憑證的時候都必須驗證 DNS 所有權人,因此會需要在 DNS 中增加一筆 TXT 紀錄來驗證所有權。譬如我們在使用 Certbot 新申請憑證時可以選擇使用 DNS 來驗證 (當然還有其他種驗證方式):

[root@localhost ~]# certbot certonly --manual --preferred-challenges=dns -d big.30cm.gg
Saving debug log to /var/log/letsencrypt/letsencrypt.log
dns-01 challenge for big.30cm.gg

- - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.big.30cm.gg with the following value:

lcJcoPSHJXD-LaCGPwjEDbr78wINAll7Yd-FvsucI8g

Before continuing, verify the record is deployed.

Certbot 就會請你在 DNS 內輸入一筆 TXT 紀錄來驗證。這時如果你使用的是 Gandi 的 LiveDNS 可以用我寫的 shell script 自動將要驗證的 TXT 紀錄增加到區域檔內。

Certbot Plugins Gandi LiveDNS

https://gitlab.com/haway/certbot-plugin-dns-gandi

將這個 Script 下載到你的電腦中,就可以直接自動增加 TXT 紀錄通過驗證。

  1. 下載 Shell Script
  2. 設定執行權限 (chmod u+x)
  3. 取得您的 APIKEY ,修改 Script 中的 APIKEY 變數。
  4. 執行 Certbot
新申請憑證
certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /etc/letsencrypt/gandi/authenticator.sh -d example.com.tw

續約憑證
certbot renew --manual --preferred-challenges=dns --manual-auth-hook /etc/letsencrypt/gandi/authenticator.sh

把指令放入你的 Crontab 就可以摟!

在〈Certbot 自動續約,自動驗證 DNS 域名所有權 – LiveDNS〉中有 2 則留言

對,範例:

certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /etc/letsencrypt/gandi/authenticator.sh -d *.wildcard.example.com

發佈回覆給「 HaWay」的留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *