#author("2018-08-30T17:56:07+09:00","","") #author("2018-08-30T17:57:45+09:00","","") [[CentOS7]] *SSL証明書を取得する (Let's Encrypt) [#v8c43ed7] 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日以内に更新作業を再度実施する必要があります。 **証明書を取得するためのツール Certbot クライアントをインストールします。 [#jc5057be] |BGCOLOR(black):COLOR(white):|c |&color(lightpink){# EPELからインストール};| |[root@localhost ~]# yum --enablerepo=epel -y install certbot| **証明書を取得します。 [#ldab8823] 下例は Apache httpd や Nginx などの Webサーバーが稼働していることが前提となります。 作業を実施するサーバーで Webサーバーが稼働していない場合は次の手順を参照ください。 また、インターネット側から、作業を実施するサーバー (証明書を取得したい FQDN のサーバー) の 80 ポート宛てにアクセス可能であることも前提です。 |BGCOLOR(black):COLOR(white):|c |&color(lightpink){# [--webroot] 指定で稼働中 Web サーバーの公開ディレクトリ配下を認証用の一時領域に使用 &br; # -w [ドキュメントルート] -d [証明書を取得したいFQDN] &br; # FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記 &br; # ドキュメントルートはバーチャルホストで複数のホスト定義がある場合、該当するホスト定義のものを指定 &br; # ドキュメントルート指定の動作としては, 指定したドキュメントルート配下に &br; # [.well-known] ディレクトリが作成され, 認証用のファイルが自動的,一時的に設置されるのみ &br; # 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定 &br; # 例 : hoge.com/hoge.com の二つについて取得する場合 &br; # ⇒ -d hoge.com -d hoge.com};| |[root@localhost ~]# certbot certonly --webroot -w /var/www/html -d hoge.com| |Saving debug log to /var/log/letsencrypt/letsencrypt.log &br; Plugins selected: Authenticator webroot, Installer None &br; Enter email address (used for urgent renewal and security notices) &br; &color(lime){# 初回のみメールアドレスの登録と利用条件への同意が必要 &br; # 受信可能なメールアドレスを指定}; &br; (Enter 'c' to cancel): root@hoge.com &br; Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org &br; &br; ------------------------------------------------------------------------------- &br; Please read the Terms of Service at &br; https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must &br; agree in order to register with the ACME server at &br; https://acme-v01.api.letsencrypt.org/directory &br; ------------------------------------------------------------------------------- &br; &color(lightpink){# 利用条件に同意する}; &br; (A)gree/(C)ancel: A &br; &br; ------------------------------------------------------------------------------- &br; Would you be willing to share your email address with the Electronic Frontier &br; Foundation, a founding partner of the Let's Encrypt project and the non-profit &br; organization that develops Certbot? We'd like to send you email about EFF and &br; our work to encrypt the web, protect its users and defend digital rights. &br; ------------------------------------------------------------------------------- &br; &color(lightpink){# 非営利団体 Electronic Frontier Foundation にもメールアドレスを登録するか否か}; &br; (Y)es/(N)o: Y &br; Starting new HTTPS connection (1): supporters.eff.org &br; Obtaining a new certificate &br; Performing the following challenges: &br; http-01 challenge for hoge.com &br; Using the webroot path /var/www/html for all unmatched domains. &br; Waiting for verification... &br; Cleaning up challenges &br; &br; IMPORTANT NOTES: &br; - Congratulations! Your certificate and chain have been saved at: &br; /etc/letsencrypt/live/hoge.com/fullchain.pem &br; Your key file has been saved at: &br; /etc/letsencrypt/live/hoge.com/privkey.pem &br; Your cert will expire on 2018-05-22. To obtain a new or tweaked &br; version of this certificate in the future, simply run certbot &br; again. To non-interactively renew *all* of your certificates, run &br; "certbot renew" &br; - Your account credentials have been saved in your Certbot &br; configuration directory at /etc/letsencrypt. You should make a &br; secure backup of this folder now. This configuration directory will &br; also contain certificates and private keys obtained by Certbot so &br; making regular backups of this folder is ideal. &br; - If you like Certbot, please consider supporting our work by: &br; &br; Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate &br; Donating to EFF: https://eff.org/donate-le &br; &br; &color(lightpink){# [Congratulations] と表示さえれば成功 &br; # メッセージ中に記載の通り [/etc/letsencrypt/live/(FQDN)/] 配下に証明書が取得されている &br; &br; # cert.pem ⇒ SSLサーバー証明書(公開鍵含む) &br; # chain.pem ⇒ 中間証明書 &br; # fullchain.pem ⇒ cert.pem と chain.pem が結合されたファイル &br; # privkey.pem ⇒ 公開鍵に対する秘密鍵| |&color(lightpink){# [--webroot] 指定で稼働中 Web サーバーの公開ディレクトリ配下を認証用の一時領域に使用 &br; # -w [ドキュメントルート] -d [証明書を取得したいFQDN] &br; # FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記 &br; # ドキュメントルートはバーチャルホストで複数のホスト定義がある場合、該当するホスト定義のものを指定 &br; # ドキュメントルート指定の動作としては, 指定したドキュメントルート配下に &br; # [.well-known] ディレクトリが作成され, 認証用のファイルが自動的,一時的に設置されるのみ &br; # 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定 &br; # 例 : hoge.com/www.hoge.com の二つについて取得する場合 &br; # ⇒ -d hoge.com -d www.hoge.com};| |[root@localhost ~]# certbot certonly --webroot -w /var/www/html -d www.hoge.com| |Saving debug log to /var/log/letsencrypt/letsencrypt.log &br; Plugins selected: Authenticator webroot, Installer None &br; Enter email address (used for urgent renewal and security notices) &br; &color(lime){# 初回のみメールアドレスの登録と利用条件への同意が必要 &br; # 受信可能なメールアドレスを指定}; &br; (Enter 'c' to cancel): root@mail.hoge.com &br; Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org &br; &br; ------------------------------------------------------------------------------- &br; Please read the Terms of Service at &br; https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must &br; agree in order to register with the ACME server at &br; https://acme-v01.api.letsencrypt.org/directory &br; ------------------------------------------------------------------------------- &br; &color(lightpink){# 利用条件に同意する}; &br; (A)gree/(C)ancel: A &br; &br; ------------------------------------------------------------------------------- &br; Would you be willing to share your email address with the Electronic Frontier &br; Foundation, a founding partner of the Let's Encrypt project and the non-profit &br; organization that develops Certbot? We'd like to send you email about EFF and &br; our work to encrypt the web, protect its users and defend digital rights. &br; ------------------------------------------------------------------------------- &br; &color(lightpink){# 非営利団体 Electronic Frontier Foundation にもメールアドレスを登録するか否か}; &br; (Y)es/(N)o: Y &br; Starting new HTTPS connection (1): supporters.eff.org &br; Obtaining a new certificate &br; Performing the following challenges: &br; http-01 challenge for www.hoge.com &br; Using the webroot path /var/www/html for all unmatched domains. &br; Waiting for verification... &br; Cleaning up challenges &br; &br; IMPORTANT NOTES: &br; - Congratulations! Your certificate and chain have been saved at: &br; /etc/letsencrypt/live/www.hoge.com/fullchain.pem &br; Your key file has been saved at: &br; /etc/letsencrypt/live/www.hoge.com/privkey.pem &br; Your cert will expire on 2018-05-22. To obtain a new or tweaked &br; version of this certificate in the future, simply run certbot &br; again. To non-interactively renew *all* of your certificates, run &br; "certbot renew" &br; - Your account credentials have been saved in your Certbot &br; configuration directory at /etc/letsencrypt. You should make a &br; secure backup of this folder now. This configuration directory will &br; also contain certificates and private keys obtained by Certbot so &br; making regular backups of this folder is ideal. &br; - If you like Certbot, please consider supporting our work by: &br; &br; Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate &br; Donating to EFF: https://eff.org/donate-le &br; &br; &color(lightpink){# [Congratulations] と表示さえれば成功 &br; # メッセージ中に記載の通り [/etc/letsencrypt/live/(FQDN)/] 配下に証明書が取得されている &br; &br; # cert.pem ⇒ SSLサーバー証明書(公開鍵含む) &br; # chain.pem ⇒ 中間証明書 &br; # fullchain.pem ⇒ cert.pem と chain.pem が結合されたファイル &br; # privkey.pem ⇒ 公開鍵に対する秘密鍵| 作業を実施するサーバーで Webサーバーが稼働していない場合でも、Certbot の簡易 Webサーバー機能を使用して証明書の取得が可能です。 いずれにしろ、インターネット側から当作業を実施するサーバーの 80 ポート宛てにアクセス可能であることは前提となります。 |BGCOLOR(black):COLOR(white):|c |&color(lightpink){# [--standalone] 指定で Certbot の簡易 Webサーバー機能を使用 &br; # -d [証明書を取得したいFQDN] &br; # FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記 &br; # 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定 &br; # 例 : hoge.com/hoge.com について取得する場合 ⇒ -d hoge.com -d hoge.com};| |[root@localhost ~]# certbot certonly --standalone -d hoge.com| |Saving debug log to /var/log/letsencrypt/letsencrypt.log &br; Plugins selected: Authenticator standalone, Installer None &br; Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org &br; Obtaining a new certificate &br; Performing the following challenges: &br; http-01 challenge for hoge.com &br; Waiting for verification... &br; Cleaning up challenges &br; &br; IMPORTANT NOTES: &br; - Congratulations! Your certificate and chain have been saved at: &br; /etc/letsencrypt/live/hoge.com/fullchain.pem &br; Your key file has been saved at: &br; /etc/letsencrypt/live/hoge.com/privkey.pem &br; Your cert will expire on 2018-05-22. To obtain a new or tweaked &br; version of this certificate in the future, simply run certbot &br; again. To non-interactively renew *all* of your certificates, run &br; "certbot renew" &br; - If you like Certbot, please consider supporting our work by: &br; &br; Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate &br; Donating to EFF: https://eff.org/donate-le| |&color(lightpink){# [--standalone] 指定で Certbot の簡易 Webサーバー機能を使用 &br; # -d [証明書を取得したいFQDN] &br; # FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記 &br; # 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定 &br; # 例 : hoge.com/www.hoge.com について取得する場合 ⇒ -d hoge.com -d hoge.com};| |[root@localhost ~]# certbot certonly --standalone -d mail.hoge.com| |Saving debug log to /var/log/letsencrypt/letsencrypt.log &br; Plugins selected: Authenticator standalone, Installer None &br; Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org &br; Obtaining a new certificate &br; Performing the following challenges: &br; http-01 challenge for mail.hoge.com &br; Waiting for verification... &br; Cleaning up challenges &br; &br; IMPORTANT NOTES: &br; - Congratulations! Your certificate and chain have been saved at: &br; /etc/letsencrypt/live/mail.hoge.com/fullchain.pem &br; Your key file has been saved at: &br; /etc/letsencrypt/live/mail.hoge.com/privkey.pem &br; Your cert will expire on 2018-05-22. To obtain a new or tweaked &br; version of this certificate in the future, simply run certbot &br; again. To non-interactively renew *all* of your certificates, run &br; "certbot renew" &br; - If you like Certbot, please consider supporting our work by: &br; &br; Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate &br; Donating to EFF: https://eff.org/donate-le| 取得済みの証明書を更新する場合は以下のように実行します。 |BGCOLOR(black):COLOR(white):|c |&color(lightpink){# 有効期限が 30日未満の証明書を全て更新 &br; # 有効期限の残り日数に関わらず更新したい場合は [--force-renew] を合わせて指定| |[root@localhost ~]# certbot renew|