Let’s EncryptのSSL証明書を更新する方法

以前Let’s Encryptを使用してNginxにSSL接続を行う方法を書きましたが、Let’s EncryptSSL証明書は有効期限が3ヶ月で終了してしまいます。

有効期限が切れる前にSSL証明書の更新が必要なのですが、今回は手動で更新する方法を書きます。

この記事でわかること
  • Let’s EncryptのSSL証明書更新のしかた
目次

前提条件

今回はSSL証明書の更新のしかたになりますので、以下の状態を前提で進めていきます。

前提条件
  • SSH接続でWebサーバーに接続可能
  • Let’s EncryptのSSL証明書を取得して設定済
  • cron等を使った自動更新については今回は触れない

サーバーの構築方法や、Let’s EncryptでNginxにSSL接続の導入方法は過去記事を参照ください。

SSL証明書更新準備

SSL証明書の有効期限を確認する

Let’s EncryptのSSL証明書は有効期限の30日未満から更新が可能となります。

強制的に更新する方法もありますが、まずは有効期限の確認をしましょう。

SSL証明書有効期限確認コマンド

$ cd /usr/local 
$ ./certbot/certbot-auto certificates

/usr/local は certbotをインストールしたディレクトリに移動してください。
certbot-autoを$PATHに通してる場合はもちろん必要ないです。

実行するとこんな感じで有効期限が表示されます。

$ cd /usr/local 
$ ./certbot/certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: hirooooo-lab.com
    Domains: hirooooo-lab.com
    Expiry Date: 2020-04-05 02:57:28+00:00 (VALID: 18 days)
    Certificate Path: /etc/letsencrypt/live/hirooooo-lab.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/hirooooo-lab.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

更新のdry-run(リハーサル)

実際にLet’s EncryptのSSL証明書の更新を行う前に、リハーサル更新を行ってエラーの有無を確認します。

dry-run(リハーサル)では実際には証明書の更新は行われません。

$ ./certbot/certbot-auto renew --dry-run

–dry-runというオプションによりリハーサルとなりますので、忘れずにつけましょう。

実行するとズラーッと下記のように表示されると思います。

$ ./certbot/certbot-auto renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/hirooooo-lab.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for hirooooo-lab.com
Using the webroot path /usr/share/nginx/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/hirooooo-lab.com/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/hirooooo-lab.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ここで重要なのは25行目の

Congratulations, all renewals succeeded. The following certs have been renewed:

と表示されていればリハーサルは成功です。

SSL証明書更新の実行

有効期限の確認やリハーサルでエラーなしを確認したら実際にLet’s EncryptのSSL証明書を更新してみましょう。

Let’s EncryptのSSL証明書更新

更新コマンドはリハーサルのコマンドから–dry-runを取り除いたコマンドとなります。

$ ./certbot/certbot-auto renew

このコマンドでは有効期限が30未満となっているときに更新可能となります。

実際に更新してみるとこうなります。

$ ./certbot/certbot-auto renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/hirooooo-lab.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for hirooooo-lab.com
Using the webroot path /usr/share/nginx/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/hirooooo-lab.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/hirooooo-lab.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

dry-runのときと基本的には同じですね。

こちらも[Congratulations, all renewals succeeded. The following certs have been renewed:]が表示されていれば更新成功となっています。

更新後の有効期限の確認

更新が完了したら再度有効期限の確認をしてみましょう。

$ ./certbot/certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: hirooooo-lab.com
    Domains: hirooooo-lab.com
    Expiry Date: 2020-06-15 23:20:18+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/hirooooo-lab.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/hirooooo-lab.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

有効期限が3ヶ月更新されたのが確認できると思います。

強制的に更新する方法

certbot-auto renewコマンドでは有効期限が30日未満の場合に更新が可能ですが、30日以上の場合に強制的に更新するには–force-renewオプションを付けて実行します。

$ ./certbot/certbot-auto renew --force-renew

Webサーバーの再起動を忘れずに

Let’s EncryptのSSL証明書の更新が完了したらWebサーバーの再起動が必要です。

Nginxの場合は忘れずに以下の再起動コマンドを実行しましょう。

Nginxの再起動コマンド

$ sudo systemctl restart nginx

これでLet’s Encryptを使用したNginxのSSL証明書の更新が完了です。

あとはまた3ヶ月の有効期限が切れる前にSSL証明書の更新を行いましょう。

自動更新の参考リンク

毎回3ヶ月ごとに手動で実行するのが面倒な人は、cronを使用した自動更新の方法があるのでこちらのリンクとかを参考にやってみてください。

Let’s EncryptのSSL証明書更新まとめ

今回ざっとLet’s EncryptのSSL証明書を手動更新する方法を書いてみました。

基本的にはsertbot-autoコマンドだけでできるので、Let’s Encryptの導入が済んでいる人は簡単にできたと思います。

ただ、3ヶ月ごとに毎回の手動更新はやはり手間なので、cronで自動化するのが現実的かなと思います。

Let’s EncryptでSSL対応をする人の少しでも参考になれば幸いです。

まとめ
  • 期限を確認するのはsertbot-auto certificates
  • SSL証明書を更新するにはsertbot-auto renew
  • リハーサルは renew に–dry-runオプション
  • 有効期限30日以前に強制実行は–force-renewオプション
  • でもやっぱり自動更新にした方がいいと思う

サーバー構築にオススメのVPS

気軽にサーバーを構築したい場合に、すぐに使えるConoha VPSがオススメです!

SSDの高速サーバーが初期費用無料で低価格でサーバーを持つことができます。

プランリニューアル&容量増量!【衝撃価格】月額620円のConoHa VPS【512MBプラン】

私も実際にConohaVPSを使ってますが、値段的にも機能的にもオススメできるVPSサービスです。


おすすめ本
よかったらシェアしてね!

コメント

コメント一覧 (1件)

コメントする

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)

目次
閉じる