概要
無料で利用可能なSSL証明書Let’s Encrypt(レッツ・エンクリプト)を導入しSSL接続を可能にする
なお、SSL証明書は個別で作成する
certbotとcertbot-autoインストール
certbotとcertbot-autoのインストール
すでに導入済みである人は割愛してください
certbotインストール
# yum -y install python2-certbot-apache
certbot-autoインストール
# cd /usr/local/bin/
# wget https://dl.eff.org/certbot-auto
--2019-07-20 15:22:08-- https://dl.eff.org/certbot-auto
dl.eff.org (dl.eff.org) をDNSに問いあわせています... 151.101.108.201, 2a04:4e42:36::201
dl.eff.org (dl.eff.org)|151.101.108.201|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 68023 (66K) [application/octet-stream]
`certbot-auto' に保存中
100%[======================================>] 68,023 --.-K/s 時間 0.04s
2019-07-20 15:22:08 (1.73 MB/s) - `certbot-auto' へ保存完了 [68023/68023]
# ls -l certbot-auto
-rw-r--r-- 1 root root 68023 7月 20 04:19 certbot-auto
# chmod a+x certbot-auto
# ls -l certbot-auto
-rwxr-xr-x 1 root root 68023 7月 20 04:19 certbot-auto
# which certbot-auto
/usr/local/bin/certbot-auto
SSL証明書発行
SSL証明書発行
# certbot-auto certonly --webroot \
-w <ドキュメントルート> -d <ドメイン名> --email <メールアドレス>
出力結果
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for <ドメイン名>
Using the webroot path <ドキュメントルート> for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/<ドメイン名>/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/<ドメイン名>/privkey.pem
Your cert will expire on 2019-12-07. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto 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
SSL証明書確認
SSL証明書確認
# ls -l /etc/letsencrypt/live/<ドメイン名>
-rw-r--r-- 1 root root 692 9月 8 15:49 /etc/letsencrypt/live/<ドメイン名>/README
lrwxrwxrwx 1 root root 50 9月 8 15:49 /etc/letsencrypt/live/<ドメイン名>/cert.pem -> ../../archive/takeda.pineapplefanboy.com/cert1.pem
lrwxrwxrwx 1 root root 51 9月 8 15:49 /etc/letsencrypt/live/<ドメイン名>/chain.pem -> ../../archive/takeda.pineapplefanboy.com/chain1.pem
lrwxrwxrwx 1 root root 55 9月 8 15:49 /etc/letsencrypt/live/<ドメイン名>/fullchain.pem -> ../../archive/takeda.pineapplefanboy.com/fullchain1.pem
lrwxrwxrwx 1 root root 53 9月 8 15:49 /etc/letsencrypt/live/<ドメイン名>/privkey.pem -> ../../archive/takeda.pineapplefanboy.com/privkey1.pem
SSL証明書更新
SSL証明書更新
# certbot-auto renew --force-renewal --dry-run
出力結果
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/<ドメイン名>.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for <ドメイン名>
Using the webroot path <ドキュメントルート> for all unmatched domains.
Waiting for verification...
Cleaning up challenges
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/<ドメイン名>/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/<ドメイン名>/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- 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.
SSL証明書自動更新(cron)
SSL証明書自動更新(cron)
# Apache httpd を利用している場合の例 (CentOS 6 の場合)
00 04 01 * * certbot renew && service httpd restart
# Apache httpd を利用している場合の例 (CentOS 7 の場合)
00 04 01 * * certbot renew && systemctl restart httpd
↓こっちでもOK
00 04 01 * * /usr/bin/certbot renew --post-hook "systemctl restart httpd.service"
補足
証明書を消す場合
# certbot-auto delete -d <ドメイン名>
ドキュメントルートいらない場合のcertbot-autoコマンド
メールサーバ用のSSLとか
# certbot-auto certonly --webroot \
-d <ドメイン名> --email <メールアドレス>
参考リンク
Let’s Encrypt サーバー証明書の取得と自動更新設定メモ
ありがとうございます
コメント