GPG 代理不会从密钥环中删除我的 SSH 密钥

Naf*_*Kay 23 ssh gpg-agent

我有一个非常麻烦的问题。我无法gpg-agent从它的密钥环中删除我的 SSH 密钥,它甚至在多次重启后仍然存在。

$ ssh-add -D
SSH_AGENT_FAILURE
Failed to remove all identities.
Run Code Online (Sandbox Code Playgroud)

即使我告诉它删除身份:

$ ssh-add -d /path/to/private/key
Identity removed: /path/to/private/key
Run Code Online (Sandbox Code Playgroud)

然后我看

$ ssh-add -l
4096 1b:cb:52:a6:e5:13:e6:78:14:12:92:8f:34:8f:92:88 /path/to/private/key
Run Code Online (Sandbox Code Playgroud)

它仍然存在。

这是缓存在哪里?它似乎出于某种原因写入磁盘,这对于 SSH 代理来说是一件可怕的事情。我正在运行以下开始gpg-agent:

gpg-agent --enable-ssh-support --daemon 
Run Code Online (Sandbox Code Playgroud)

其他一切正常,但它将此文件缓存在某处,我需要将其删除。

小智 23

是的,这似乎ssh -d与 gpg 的代理有关。这是使用不同命令的解决方法。

gpg-connect-agent从命令行运行命令以连接到代理。然后,根据那里的提示,输入此命令以列出 ssh 密钥

KEYINFO --ssh-list --ssh-fpr
Run Code Online (Sandbox Code Playgroud)

你应该看到类似的东西:

S KEYINFO 3365433C34421CC53B52C9A82169FD2328CF610B D - - - P df:a2:36:8d:ad:88:b3:cc:00:96:10:d4:c9:2c:e0:df - S
OK
Run Code Online (Sandbox Code Playgroud)

现在,要从代理中删除:

DELETE_KEY 3365433C34421CC53B52C9A82169FD2328CF610B
Run Code Online (Sandbox Code Playgroud)

它会说:

OK
Run Code Online (Sandbox Code Playgroud)

现在,使用 BYE 命令退出:

BYE OK 关闭连接

现在,用 验证,ssh-add -l你会看到它真的消失了。


lar*_*sks 16

与大多数 GPG 一样,ssh 凭据缓存在.gnupg目录中,特别是在 中~/.gnupg/sshcontrol,它看起来像这样:

# List of allowed ssh keys.  Only keys present in this file are used
# in the SSH protocol.  The ssh-add tool may add new entries to this
# file to enable them; you may also add them manually.  Comment
# lines, like this one, as well as empty lines are ignored.  Lines do
# have a certain length limit but this is not serious limitation as
# the format of the entries is fixed and checked by gpg-agent. A
# non-comment line starts with optional white spaces, followed by the
# keygrip of the key given as 40 hex digits, optionally followed by a
# the caching TTL in seconds and another optional field for arbitrary
# flags.   Prepend the keygrip with an '!' mark to disable it.

# Key added on: 2013-09-19 22:15:50
# Fingerprint:  8b:56:b0:3f:c8...
681BF1EFF... 0
# Key added on: 2013-09-20 17:14:36
# Fingerprint:  4b:cb:7e:b0:d7...
F7BCEBD1C... 0
Run Code Online (Sandbox Code Playgroud)

正如评论所说,您可以通过删除键来删除它们,或者使用!. 我没有测试过,但我想“禁用”一个键意味着你不能在不编辑文件的情况下显式启用它或添加它。

  • 这些只是关键指纹。~/.gnupg/private-keys-v1.d/中还有私钥存储 (3认同)