certbotで特定のドメインの証明書と設定を削除
無料でSSL証明書(Let’s Encrypt証明書)を発行しているcertbotで運用しているドメインを廃止したりして、特定のドメインのみ不要になるケースがあります。
不要になったドメインのSSL証明書及び設定を削除するには、certbotの「delete」オプションを利用します。
本記事では、certbotで発行した特定のドメインの設定削除及びSSL証明書を削除する方法を紹介します
1.現在に管理されている証明書の一覧と、それぞれの「Certificate Name(証明書名)」を確認します。
$ sudo certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: example.jp
Serial Number: 641949a06f8184cd5c7a87921d12478129e
Key Type: RSA
Domains: example.jp
Expiry Date: 2026-04-18 12:22:17+00:00 (VALID: 47 days)
Certificate Path: /etc/letsencrypt/live/example.jp/fullchain.pem
Private Key Path: /etc/letsencrypt/live/example.jp/privkey.pem
2.既存のSSL証明書をバックアップします。以下の場合は特定のドメインのみバックアップしています。
$ sudo tar -czvf certs_backup_$(date +%Y%m%d).tar.gz /etc/letsencrypt
個別のドメインのみバックアップだと以下の構成になります。tarで圧縮した方が実行するコマンドも少ないのでお勧めです
/etc/letsencrypt/archive/:証明書と秘密鍵の実体/etc/letsencrypt/live/:最新版の実体を参照するシンボリックリンク/etc/letsencrypt/renewal/:更新タイミングや設定を記録した設定ファイル
# 最低限、Apacheに起動に必要なSSL証明書のみバックアップします $ sudo cp -pr /etc/letsencrypt/archive .
3.不要になったドメインの証明書を削除
$ sudo certbot delete --cert-name example.jp Are you sure you want to delete the above certificate(s)? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y Deleted all files relating to certificate example.jp.
SSL証明書名を指定しない場合は以下のように削除するドメインを選択して削除する方向になります
$ sudo certbot delete Saving debug log to /var/log/letsencrypt/letsencrypt.log Which certificate(s) would you like to delete? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: example.jp 2: www.example.jp 3: example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):

