有馬総一郎のブログ

(彼氏の事情)

2021年02月22日 23:09:52 JST - 2 minute read - Comments - Linux

GPG鍵をReal nameまたはEmail addressで指定しても復号・削除できない

GPG鍵をReal nameまたはEmail addressで指定しても削除できなくなった。もしくは、それまでgpg -d ~/.config/neomutt/passwds.gpgで復号できてたのができなくなった。

$ gpg --delete-secret-keys gpg_real_name
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: 鍵"gpg_real_name"が見つかりません
gpg: gpg_real_name: delete key failed: 見つかりません
$ gpg --delete-secret-keys xxxxxxxxx@gmail.com
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: 鍵"gpg_real_name"が見つかりません
gpg: gpg_real_name: delete key failed: 見つかりません
$ neomutt
gpg: 3072-ビットRSA鍵, ID 90ABCDEF12345678, 日付2021-02-18に暗号化されました
      "gpg_real_name <xxxxxxxxx@gmail.com>"
gpg: 復号に失敗しました: 秘密鍵がありません

なんてことはない、秘密鍵だけをgpg --delete-secret-keysして削除していたが、公開鍵が残った状態のまま、新しいGPG鍵ペアを生成をしていて、Real nameやEmail Addressが一意でなくなっていたためだった。

$ gpg --list-keys
/home/gpg_real_name/.gnupg/pubring.kbx
-----------------------------------
pub   rsa3072 2021-02-18 [SC] [有効期限: 2023-02-18]
      1234567890ABCDEF1234567890ABCDEF12345678
uid           [  究極  ] gpg_real_name <xxxxxxxxx@gmail.com>
sub   rsa3072 2021-02-18 [E] [有効期限: 2023-02-18]

pub   rsa3072 2021-02-18 [SC] [有効期限: 2023-02-18]
      ABCDEF1234567890ABCDEF1234567890ABCDEF12
uid           [  究極  ] gpg_real_name <xxxxxxxxx@gmail.com>
sub   rsa3072 2021-02-18 [E] [有効期限: 2023-02-18]

この場合、キーIDを指定すれば削除できる。

$ gpg --delete-keys 1234567890ABCDEF1234567890ABCDEF12345678
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


pub  rsa3072/90ABCDEF12345678 2021-02-18 gpg_real_name <xxxxxxxxx@gmail.com>

この鍵を鍵リングから削除しますか? (y/N) y

秘密鍵と公開鍵を一緒に削除するオプションもある--delete-secret-and-public-key

$ gpg --delete-secret-and-public-key gpg_real_name
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


sec  rsa3072/210FDCBA09876543 2021-02-18 gpg_real_name <xxxxxxxxx@gmail.com>

この鍵を鍵リングから削除しますか? (y/N) y
これは秘密鍵です! 本当に削除しますか? (y/N) y

pub  rsa3072/210FDCBA09876543 2021-02-18 gpg_real_name <xxxxxxxxx@gmail.com>

この鍵を鍵リングから削除しますか? (y/N) y

秘密鍵だけ削除して、公開鍵だけ残す場合って、どんなケースがあるんだろうか。不勉強につき分からない。