CentOS7

SSL証明書を取得する (Let's Encrypt)

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 クライアントをインストールします。

# EPELからインストール
[root@localhost ~]# yum --enablerepo=epel -y install certbot

証明書を取得します。

下例は Apache httpd や Nginx などの Webサーバーが稼働していることが前提となります。

作業を実施するサーバーで Webサーバーが稼働していない場合は次の手順を参照ください。

また、インターネット側から、作業を実施するサーバー (証明書を取得したい FQDN のサーバー) の 80 ポート宛てにアクセス可能であることも前提です。

# [--webroot] 指定で稼働中 Web サーバーの公開ディレクトリ配下を認証用の一時領域に使用
# -w [ドキュメントルート] -d [証明書を取得したいFQDN]
# FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記
# ドキュメントルートはバーチャルホストで複数のホスト定義がある場合、該当するホスト定義のものを指定
# ドキュメントルート指定の動作としては, 指定したドキュメントルート配下に
# [.well-known] ディレクトリが作成され, 認証用のファイルが自動的,一時的に設置されるのみ
# 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定
# 例 : hoge.com/www.hoge.com の二つについて取得する場合
# ⇒ -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
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices)
# 初回のみメールアドレスの登録と利用条件への同意が必要
# 受信可能なメールアドレスを指定

(Enter 'c' to cancel): root@mail.hoge.com
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
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-v01.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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
# 非営利団体 Electronic Frontier Foundation にもメールアドレスを登録するか否か
(Y)es/(N)o: Y
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.hoge.com
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/www.hoge.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.hoge.com/privkey.pem
Your cert will expire on 2018-05-22. 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

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

# cert.pem ⇒ SSLサーバー証明書(公開鍵含む)
# chain.pem ⇒ 中間証明書
# fullchain.pem ⇒ cert.pem と chain.pem が結合されたファイル
# privkey.pem ⇒ 公開鍵に対する秘密鍵

作業を実施するサーバーで Webサーバーが稼働していない場合でも、Certbot の簡易 Webサーバー機能を使用して証明書の取得が可能です。 いずれにしろ、インターネット側から当作業を実施するサーバーの 80 ポート宛てにアクセス可能であることは前提となります。

# [--standalone] 指定で Certbot の簡易 Webサーバー機能を使用
# -d [証明書を取得したいFQDN]
# FQDN (Fully Qualified Domain Name) : ホスト名.ドメイン名を省略なしで表記
# 証明書を取得したいFQDNが複数ある場合は、-d [証明書を取得したいFQDN] を複数指定
# 例 : 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
Plugins selected: Authenticator standalone, Installer None
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mail.hoge.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mail.hoge.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mail.hoge.com/privkey.pem
Your cert will expire on 2018-05-22. 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

取得済みの証明書を更新する場合は以下のように実行します。

&color(lightpink){# 有効期限が 30日未満の証明書を全て更新
# 有効期限の残り日数に関わらず更新したい場合は [--force-renew] を合わせて指定
[root@localhost ~]# certbot renew

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-08-30 (木) 17:57:46