我使用 FIDO2 在 Yubikey 5 Nano 上创建了 SSH key :
ssh-keygen -t ed25519-sk -f ~/.ssh/id_ed25519-sk
Yubikey 设置了用户和管理员 PIN。然而,当使用 key 建立 SSH 连接时,没有像 Github 博客 Security keys are now supported for SSH Git operations 上那样要求触摸 key 的消息。 :
Confirm user presence for key ...
在详细模式下,SSH 客户端显示:debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /.../.ssh/id_ed25519-sk ED25519-SK SHA256:... explicit authenticator agent
debug1: Server accepts key: /.../.ssh/id_ed25519-sk ED25519-SK SHA256:... explicit authenticator agent
此时 Yubikey 开始闪烁。一旦我触摸它,SSH 登录就会使用该 key 成功,随后的消息将是:debug1: Authentication succeeded (publickey).
Authenticated to github.com (via proxy).
当使用 git clone
等 Git 操作的 key 时或 git pull
,它只是默默地等待按键。这种行为的问题是我不知道 SSH 客户端是在等待网络/服务器/代理还是让我触摸 key 。这是在带有 OpenSSH 8.2p1(和 Git 2.28.0)的 Ubuntu 20.04.4 LTS 上。我正在使用默认的 ssh-agent,我可以在 Gnome 的“OpenSSH key ”下看到“密码和 key ”应用程序中列出的 key 。
使用
ssh-keygen
从 OpenSSH 9.0p1 可移植源编译,我可以看到公钥的标志设置为 0x1(需要用户在场):$ ./ssh-keygen -vvv -y -f ~/.ssh/id_ed25519-sk
sk-ssh-ed25519@openssh.com AAAAGnNrLX...mAAAABHNzaDo= foo@bar
debug1: sk_application: "ssh:", sk_flags 0x01
该标志理论上应该触发消息,但它不会。OpenSSH 9.0p1 SSH 客户端具有相同的行为,因此我认为缺少消息是由我的设置中的某些原因引起的。
添加一些调试调试代码到
identity_sign()
在 sshconnect2.c
,我可以看到它调用了ssh_agent_sign()
并返回。查看process_sign_request2()
的源代码在 ssh-agent.c
,它包含为“sk”键发出消息的代码。当 SSH 客户端等待按键触摸时,相关的进程树如下所示:
gnome-keyring-d(57868)-+-ssh-agent(58517)---ssh-sk-helper(79174)
|-{gnome-keyring-d}(57869)
|-{gnome-keyring-d}(57870)
|-{gnome-keyring-d}(57982)
`-{gnome-keyring-d}(79173)
一旦按键发生,ssh-sk-helper
过程消失。所以看起来如果
ssh-agent
发出消息,它没有到达 ssh
过程。
最佳答案
这更像是一种解决方法,而不是正确的答案,但是它提供了一种修复行为的方法。这有多个因素(原文如此!):
首先,在 Ubuntu 中有一些东西会自动在 ~/.ssh
中添加 key 。目录到 ssh-agent
登录时开始 - 一旦我使用 ssh-keygen
创建 key , key 自动出现在 ssh-add -l
的输出中.可能不是ssh本身,因为我没有AddKeysToAgent
设置在我的 ~/.ssh/config
(或全局配置),该指令的默认值为 no
.
为了克服这种行为,我在不同的位置(~/altssh
)生成了 key 文件。
接下来,ssh 更喜欢存储在 ssh-agent 中的 key ,因此这也需要更改,使用 IdentitiesOnly
指令设置为 yes
.
发出“确认用户存在”消息的 ssh 配置片段:
Host *github.com
User git
# ssh will prefer the keys stored in ssh-agent to the one from
# the identity file so this behavior needs to be changed.
IdentitiesOnly yes
# for a good measure
IdentityAgent none
# The keys from ~/.ssh will be added to the ssh-agent automatically
# which I want to avoid because then the 'Confirm user presence'
# message will not be displayed.
IdentityFile ~/altssh/id_ed25519-sk
有了这个,它就可以工作了:$ ssh-add -l | grep 25519 | wc -l
0
$ ssh -T github.com
Confirm user presence for key ED25519-SK SHA256:...
Hi ...! You've successfully authenticated, but GitHub does not provide shell access.
不过,我认为这是 ssh-agent 通信在 OpenSSH 中工作方式的一个限制。另外,也许 Ubuntu 不应该添加 sk
ssh-agent 的 key 作为第二级解决方法。
关于ubuntu - "Confirm user presence for key"使用 Yubikey 进行 SSH 连接时不显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72545585/