【SSL証明書】AWS上でのCertbot手動更新方法


やること

https化で取得していたSSL証明書(90日間)が切れてしまったので、
Certbotでの手動更新を行う。

小難しいことはなく、至って簡単でした。
*既にcertbotでの設定は終えている想定となります。

備忘録的な感じなので、ご理解ください。

背景 及び 簡単な状況説明

  • AWSを使用して、PFをデプロイしている。

  • 久しぶりに開いてみたら、SSL期限切れのためPFが開けず。

  • https化のためにCertbotを使用している。

  • Certbotを使用してLet's Encrypt認証局からSSL証明書を取得している。

  • ただ、期日は90日間しかないため、証明書が切れた。

  • Certbotの設定でnginxを再起動すれば更新できる。

  • だが、cronを使用してCertbotを自動更新することもできたが、イマイチ動いておらず。cronの再起動をしていなかったからかと思われる。

なので、せっかくなら、手動でやってみようと思い実行してみました。

更新方法(手動)

①EC2に接続する

まずは、awsのターミナルでEC2に接続します。

AmazonLinux2
ssh -i ~/.ssh/****.pem ec2-user@[IPアドレス] 

②helpコマンドでcertbotに関して確認

-hでcertbotで打てるコマンドを確認してみます。

AmazonLinux2
$ certbot -h 

実行すると以下のように、バーと出てきます。

AmazonLinux2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate. The most common SUBCOMMANDS and flags are:

obtain, install, and renew certificates:
    (default) run   Obtain & install a certificate in your current webserver
    certonly        Obtain or renew a certificate, but do not install it
    renew           Renew all previously obtained certificates that are near
expiry
    enhance         Add security enhancements to your existing configuration
   -d DOMAINS       Comma-separated list of domains to obtain a certificate for
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

中身を確認していくと、下記の記述を発見!

AmazonLinux2
  renew    Renew all previously obtained certificates that are near expiry

訳すと、以前に取得した証明書を新しく(取得)すると書いてあります。

これならうまくいきそう。

③certbot renewを実行

②で見つけたコマンドで実行してみます。

AmazonLinux2
$ certbot renew

The following error was encountered:
[Errno 13] Permission denied: '/var/log/letsencrypt/.certbot.lock'
Either run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.

あれ、うまくいかない、、、

よく見てみると、Permission deniedと書いてあります。
実行許可がないためなので、sudoを付けて再実行します。

$ sudo certbot renew

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/answer-ly.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate for answer-ly.com
Performing the following challenges:
http-01 challenge for answer-ly.com
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/answer-ly.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all renewals succeeded: 
  /etc/letsencrypt/live/answer-ly.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Suucessと出力されました。
これで無事PFも開けるようになりました。

以上です。