これまでは、当サイトのみの運用だったので、ドメイン証明書も1つでしたが、WordPressでサイトを追加するためサブドメインを作成・追加したのでドメイン証明書も追加する必要がありました。
そこで、管理を容易にするためにワイルドカード証明書を作成して導入しました。
ワイルドカード証明書の更新については、手動による更新で実施することになりました。
これで、証明書の管理要領が見えたので、今まで使用していたドメイン証明書を失効させたうえで削除しようと思います。
◆失効・削除方法
証明書の失効・削除には、「certbot」コマンドを使用し、オプションに「revoke」「delete」を使用します。
・revokeオプション
# certbot revoke --cert-path /etc/letsencrypt/live/www.maruweb.jp.net/fullchain.pem
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you like to delete the certificate(s) you just revoked, along with all
earlier and later versions of the certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es (recommended)/(N)o: y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following certificate(s) are selected for deletion:
* www.maruweb.jp.net
Are you sure you want to delete the above certificate(s)?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Deleted all files relating to certificate www.maruweb.jp.net.
Congratulations! You have successfully revoked the certificate that was located at /etc/letsencrypt/live/www.maruweb.jp.net/fullchain.pem.
1行目:「certbot」コマンドに「revoke」オプションを付け、引数に「–cert-path」で証明書のパスを指定する
6,7行目:失効させた証明書を以前のバージョン等も含めて削除するか聞かれる
9行目:「y」を入力し、失効を実行する
12~16行目:削除対象の証明書確認を求められる
18行目:「y」を入力し、削除を実行する。ここで、「n」を入力すると関連するファイルは、削除されず残るので、その際は、後述する「delete」オプションを使用する
証明書の失効の確認については、後述する「証明書リストの確認」を参照
・deleteオプション
上述したように、「revoke」オプションの18行目の問い合わせで、「n」とした場合、証明書の関連ファイルは削除されないので、別途、削除する場合は下記要領で実行する。
「revoke」オプションを実行せずに「delete」オプションを実行すると、証明書の失効はされない
# certbot delete --cert-name www.maruweb.jp.net
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Which certificate(s) would you like to delete?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: maruweb.jp.net
2: www.maruweb.jp.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following certificate(s) are selected for deletion:
* www.maruweb.jp.net
Are you sure you want to delete the above certificate(s)?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Deleted all files relating to certificate www.maruweb.jp.net.
1行目:「certbot」コマンドに「delete」オプションを付け、引数に「–cert-name」で証明書のドメインを指定する
4行目:どの証明書を削除するか聞かれ、候補が表示される
6,7行目:証明書の候補が表示される。私の場合、「2」の「www.maruweb.jp.net」の証明書が削除対象となる
9,10行目:私の場合、「2」を入力する。複数削除する場合は、カンマやスペースで区切って指定する。すべての場合は、空白で実行する。キャンセルの場合は「c」を入力する。
13~17行目:削除対象の証明書確認を求められる
19行目:「y」を入力し、関連するすべてのファイルを削除する
◆参考
・ヘルプ
「certbot」コマンドのオプション等細部については、ヘルプにいろいろとある。
参照方法は、公式サイトのドキュメントでヘルプ一覧を参照するかコマンドでの参照は下記のとおり
# certbot --help
# certbot -h
# certbot -h all
# certbot -h revoke
1,2行目:「–help」「-h」で簡易ヘルプが表示される
3行目:「all」を付けるとすべての詳細ヘルプが表示される
4行目:参照したいオプション名を付けるとその項目の詳細ヘルプのみ表示される
・証明書リストの確認
# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: maruweb.jp.net
Serial Number: 4b584f54790d07df3e2642173bee338aab4
Key Type: RSA
Domains: *.maruweb.jp.net maruweb.jp.net
Expiry Date: 2021-09-10 02:52:49+00:00 (VALID: 87 days)
Certificate Path: /etc/letsencrypt/live/maruweb.jp.net/fullchain.pem
Private Key Path: /etc/letsencrypt/live/maruweb.jp.net/privkey.pem
Certificate Name: www.maruweb.jp.net
Serial Number: 486b7f628dcf3f5aaf676536e84c15fed8a
Key Type: RSA
Domains: www.maruweb.jp.net
Expiry Date: 2021-09-12 03:33:24+00:00 (INVALID: REVOKED)
Certificate Path: /etc/letsencrypt/live/www.maruweb.jp.net/fullchain.pem
Private Key Path: /etc/letsencrypt/live/www.maruweb.jp.net/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1行目:「certificates」オプションにより、証明書のリストを確認することができる。例では2つの証明書が確認できる
6,13行目:「Certificate Name」が、証明書名で、「–cert-name」に指定する際に使用する
10,17行目:「Expiry Date」が、証明書の有効期限、失効している場合は残り日数の箇所が「REVOKED」となる
11,18行目:「Certificate Path」が、証明書のパスで「–cert-path」に指定する際に使用する
・ApacheのSSL設定ファイル
# vi /etc/httpd/conf.d/ssl.conf
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
#SSLCertificateFile /etc/letsencrypt/live/marusv.maruweb.jp.net/cert.pem
#SSLCertificateFile /etc/letsencrypt/live/www.maruweb.jp.net/cert.pem
SSLCertificateFile /etc/letsencrypt/live/maruweb.jp.net/cert.pem
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
#SSLCertificateKeyFile /etc/letsencrypt/live/marusv.maruweb.jp.net/privkey.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/www.maruweb.jp.net/privkey.pem
SSLCertificateKeyFile /etc/letsencrypt/live/maruweb.jp.net/privkey.pem
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
#SSLCertificateChainFile /etc/letsencrypt/live/marusv.maruweb.jp.net/chain.pem
#SSLCertificateChainFile /etc/letsencrypt/live/www.maruweb.jp.net/chain.pem
SSLCertificateChainFile /etc/letsencrypt/live/maruweb.jp.net/chain.pem
8,9行目、18,19行目、30,31行目:それぞれ失効および削除する証明書等の記述をコメントアウト若しくは削除する
・cron設定
手動更新するためcron設定を修正する
# vi /etc/cron.d/letsencrypt
#5 0 1 * * root /usr/bin/certbot renew --force-renewal --post-hook '/usr/bin/systemctl reload httpd.service'
2行目:コメントアウトして、cronが走らないようにする
サーバ証明書の失効と削除方法について書きましたが、併せてApacheなどのWebサーバ設定ファイルの証明書類の記述および「cron」設定を修正等を忘れずに実施する必要があります。
「httpd」サービスのリロード時や「cron」が走った際にエラーとなってしまいます。