CentOS 8
Sponsored Link

SSL 証明書を取得する (Let's Encrypt)2019/12/18

 
Let's Encrypt から 発行料 無料の SSL/TLS サーバー証明書を取得します。
Let's Encrypt は Linux Foundation の協業プロジェクトで、Web 全体の安全性を改善することをミッションに掲げています。
発行料 無料 とはいえ、あやしいものではありません。
Let's Encrypt の詳細は公式サイトを参照ください。
⇒ https://letsencrypt.org/
Let's Encrypt では 一般的な ドメイン認証 (DV) の証明書を無料で発行しています。
無料ですが Let's Encrypt の中間証明書は、大手認証局 (CA) のルート証明書によってクロス署名されているため、多くの主要ブラウザ等々で信頼済みとして扱われます。
なお、一回の作業で得られる証明書の有効期限は 90日です。よって、90日以内に更新作業を再度実施する必要があります。
ただし、下例のように Snapd からインストールした Certbot パッケージであれば、Systemd の Timer が付属しているため、更新作業は自動で実行されます。
[1]
こちらを参考に Snapd をインストールしておきます
certbot-auto は version 1.10.0 以降は非推奨になり、以降はメンテナンスもされません。
公式では Snapd からのインストールが推奨されています。
[2] 証明書を取得するためのツール Certbot クライアントをインストールします。
[root@dlp ~]#
snap install certbot --classic

certbot 1.11.0 from Certbot Project (certbot-eff✓) installed
[root@dlp ~]#
ln -s /snap/bin/certbot /usr/bin/certbot

[3] 証明書を取得します。
下例は Apache httpd や Nginx などの Web サーバーが稼働していることが前提となります。
作業を実施するサーバーで Web サーバーが稼働していない場合は [4] を参照ください。
また、インターネット側から、作業を実施するサーバー (証明書を取得したい FQDN のサーバー) の 80 ポート宛てにアクセス可能であることも前提です。
# [--webroot] 指定で稼働中 Web サーバーの公開ディレクトリ配下を認証用の一時領域に使用

# -w [ドキュメントルート] -d [証明書を取得したい FQDN]

# FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記
# ドキュメントルートはバーチャルホストで複数のホスト定義がある場合、該当するホスト定義のものを指定
# 証明書を取得したい FQDN が複数ある場合は、-d [証明書を取得したい FQDN] を複数指定

# 例 : srv.world/dlp.srv.world の二つについて取得する場合

# ⇒ [-d srv.world -d dlp.srv.world]
[root@dlp ~]#
certbot certonly --webroot -w /var/www/html -d dlp.srv.world

Bootstrapping dependencies for RedHat-based OSes that will use Python3... (you can skip this with --no-bootstrap)
dnf is /usr/bin/dnf
dnf is hashed (/usr/bin/dnf)
.....
.....
# 初回のみメールアドレスの登録と利用条件への同意が必要
# 受信可能なメールアドレスを指定
Enter email address (used for urgent renewal and security notices) 
(Enter 'c' to cancel): root@mail.srv.world 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 利用条件に同意する
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for dlp.srv.world
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/dlp.srv.world/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/dlp.srv.world/privkey.pem
   Your cert will expire on 2020-03-17. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

# [Congratulations] と表示されれば成功
# メッセージ中に記載の通り [/etc/letsencrypt/live/(FQDN)/] 配下に証明書が取得されている

# cert.pem       ⇒ SSLサーバー証明書(公開鍵含む)
# chain.pem      ⇒ 中間証明書
# fullchain.pem  ⇒ cert.pem と chain.pem が結合されたファイル
# privkey.pem    ⇒ 公開鍵に対する秘密鍵
[4] 作業を実施するサーバーで Webサーバーが稼働していない場合でも、Certbot の簡易 Webサーバー機能を使用して証明書の取得が可能です。 いずれにしろ、インターネット側から当作業を実施するサーバーの 80 ポート宛てにアクセス可能であることは前提となります。
# [--standalone] 指定で Certbot の簡易 Webサーバー機能を使用

# -d [証明書を取得したい FQDN]

# FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記
# 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したい FQDN] を複数指定

# 例 : srv.world/mail.srv.world について取得する場合 ⇒ -d srv.world -d mail.srv.world
[root@dlp ~]#
certbot certonly --standalone -d mail.srv.world

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mail.srv.world
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mail.srv.world/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mail.srv.world/privkey.pem
   Your cert will expire on 2020-03-17. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
[5] 取得済みの証明書をまとめて更新する場合は、[renew] サブコマンドを使用します。
有効期限が 30日未満の証明書が全て更新されます。
有効期限の残り日数に関わらず更新したい場合は [--force-renew] を合わせて指定します。
ただし、当例のように Snapd からインストールした [certbot] クライアントであれば、更新の手動実行は必要ありません。更新は自動で実行されます。
# Snapd の Certbot パッケージはタイマーが付属

[root@dlp ~]#
systemctl status snap.certbot.renew.timer

*  snap.certbot.renew.timer - Timer renew for snap application certbot.renew
   Loaded: loaded (/etc/systemd/system/snap.certbot.renew.timer; enabled; vendo>
   Active: active (waiting) since Thu 2021-01-07 19:42:23 JST; 51min ago
  Trigger: Thu 2021-01-07 23:26:00 JST; 2h 52min left

Jan 07 19:42:23 dlp.srv.world systemd[1]: Started Timer renew for snap applicat>

# デフォルトでは以下のように毎日 2回 [renew] 実行

[root@dlp ~]#
systemctl cat snap.certbot.renew.timer

# /etc/systemd/system/snap.certbot.renew.timer
[Unit]
# Auto-generated, DO NOT EDIT
Description=Timer renew for snap application certbot.renew
Requires=var-lib-snapd-snap-certbot-889.mount
After=var-lib-snapd-snap-certbot-889.mount
X-Snappy=yes

[Timer]
Unit=snap.certbot.renew.service
OnCalendar=*-*-* 03:25
OnCalendar=*-*-* 19:26

[Install]
WantedBy=timers.target

# 手動で更新する場合は以下

[root@dlp ~]#
certbot renew

[6] Windows 向けに PKCS12 (PFX) 形式に変換するには以下のように実行します。
[root@dlp ~]#
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out dlp_for_iis.pfx

Enter Export Password:     # 任意のエクスポートパスワードを設定 
Verifying - Enter Export Password:
関連コンテンツ