SSL証明書の失効、削除をする方法をご紹介します。間違ってダウンロードしてしまって最初からやり直したいときなどに便利です。
SSL証明書の失効/削除 – 失敗パターン
証明書を物理削除しました。これでOK、、、、と思いましたが、証明された設定が残るのでは?いつまでも証明しようとして証明書が無くてエラーになるのでは?と心配になったのでネットで調べることにしました。
すると、どうやらコマンドで実行している人が多いみたいなので、習ってコマンドで削除することにします。物理削除している人はざっと見た感じいませんでした。
削除してしまった証明書の復元を試みます。幸いシンボリックリンクが張られていて実態は他のディレクトリに存在するようで助かりました。シンボリックリンクを張りなおします。
ln -s {実在するファイル名(ディレクトリ名)} {作成するリンクの名前}
# ln -s ../../archive/early2home.com/cert1.pem cert.pem [root@**** early2home.com]# ls -l total 0 lrwxrwxrwx 1 root root 38 Mar 28 13:02 cert.pem -> ../../archive/early2home.com/cert1.pem
出来ました。上記の他にも実施して復元を完了させました。
SSL証明書の失効/削除 – 成功パターン
証明書を失効させます。方法をヘルプで確認します。
# certbot -h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 --apache Use the Apache plugin for authentication & installation --standalone Run a standalone webserver for authentication (the certbot nginx plugin is not installed) --webroot Place files in a server's webroot folder for authentication --manual Obtain certificates interactively, or using shell script hooks -n Run non-interactively --test-cert Obtain a test certificate from a staging server --dry-run Test "renew" or "certonly" without saving any certificates to disk manage certificates: certificates Display information about certificates you have from Certbot revoke Revoke a certificate (supply --cert-path or --cert-name) delete Delete a certificate manage your account with Let's Encrypt: register Create a Let's Encrypt ACME account update_account Update a Let's Encrypt ACME account --agree-tos Agree to the ACME server's Subscriber Agreement -m EMAIL Email address for important account notifications More detailed help: -h, --help [TOPIC] print this message, or detailed help on a topic; the available TOPICS are: all, automation, commands, paths, security, testing, or any of the subcommands or plugins (certonly, renew, install, register, nginx, apache, standalone, webroot, etc.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
失効させるには、revokeであることを確認しました。次のコマンドを実行します。
# certbot revoke --cert-path=/etc/letsencrypt/live/early2home.com/cert.pem
するとすでに失効しているよとのこと。
Saving debug log to /var/log/letsencrypt/letsencrypt.log Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org An unexpected error occurred: Certificate already revoked Please see the logfiles in /var/log/letsencrypt for more details.
それならそれでOK。次、削除する。ヘルプを確認してコマンドを実行。
# certbot delete early2home.com usage: 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. certbot: error: unrecognized arguments: early2home.com
なぜかエラーになるログを記載を見るとオプションが足りないようだ。ヘルプにはそんなことは記載されていなかったが仕方ない。オプションをつけて実行する。
[root@**** live]# certbot delete -d early2home.com Saving debug log to /var/log/letsencrypt/letsencrypt.log Which certificate(s) would you like to delete? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: early2home.com-0001 2: early2home.com 3: www.early2home.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deleted all files relating to certificate early2home.com. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
成功しました。ドメインを指定してコマンドを実行しているにも関わらず、実行時に再度聞かれた。削除されたか確認してみます。
# ls -l total 4 -rw-r--r-- 1 root root 740 Mar 28 11:16 README drwxr-xr-x 2 root root 88 Mar 28 12:30 early2home.com-0001 drwxr-xr-x 2 root root 88 Feb 21 03:06 www.early2home.com [root@**** live]# pwd /etc/letsencrypt/live
削除されていることが確認できました。アーカイブのほうも確認します。
# ls -l archive/ total 4 drwxr-xr-x 2 root root 79 Mar 28 12:30 early2home.com-0001 drwxr-xr-x 2 root root 4096 Feb 21 03:06 www.early2home.com
アーカイブのほうも削除されていることが確認できました。
試しにearly2home.com-0001を失効してみましたが、エラーが起きなければ失効と削除を同時に実行してくれるようです。
# certbot revoke --cert-path=/etc/letsencrypt/live/early2home.com-0001/cert.pem