gpg 列表键错误 trustdb 不可写

gpg list keys error trustdb is not writable

当我尝试列出我的 gpg 密钥时出现错误:

gpg --list-keys
gpg: NOTE: trustdb not writable
gpg: checking the trustdb
gpg: trustdb rec 56: write failed (n=-1): Bad file descriptor
gpg: trustdb: sync failed: Bad file descriptor

我尝试在我的用户目录上执行递归 chown。但这似乎并没有解决问题。

卷不是只读的:

  [web1:~] bluethundr% touch test
[web1:~] bluethundr% echo hi > test
[web1:~] bluethundr% cat test
hi

所以我想知道为什么 trustdb 不可写。

我该如何解决这个问题?

这似乎已在 bug 771976

中报道过

I found this when running the command apt-key list on a machine where the root filesystem is normally mounted read-only.
This results in running gpg with "--trustdb-name", "/etc/apt//trustdb.gpg", "--list-keys".
gpg in turn attempts to create "/etc/apt//trustdb.gpg.lock" in order to lock the trustdb, which fails.

Seeing how --list-keys is an operation which shouldn't require writing to anything, having it fail in this situation is bad.

即使卷不是只读的,检查(使用 strace)gpg --list-key 试图创建它的 trustdb.gpg.lock 文件的位置。

 strace gpg --list-key | grep trustdb.gpg.lock

OP bluethundr adds :

I changed to the .gnupg directory and did a list.
I saw that the files in there were owned by root! So I did a sudo chown -R myuser:myuser *.
Then I ran gpg --list-keys again and it worked!
The problem was that the files in .gnupg were owned by root for some reason.

我已将 C 盘安装目录中 trustdb.gpg 文件的权限授予我登录时使用的用户。此后有效。