我已经使用FIDO2在Yubikey 5 Nano上创建了SSH密钥:
ssh-keygen -t ed25519-sk -f ~/.ssh/id_ed25519-sk
Yubikey设置了用户和管理PIN。
但是,在使用键建立SSH连接时,不需要像Github博客现在SSH Git操作支持安全密钥。那样访问密钥。
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登录将成功地使用该键,随后的消息将是:
debug1: Authentication succeeded (publickey).
Authenticated to github.com (via proxy).
当为Git操作(如git clone
或git pull
)使用密钥时,它只是静默地等待键点击。这种行为的问题是,我不知道SSH客户机是在等待网络/服务器/代理,还是在等待我触摸密钥。
这是在Ubuntu20.04.4LTS上使用的OpenSSH 8.2p1 (和Git 2.28.0)。我正在使用默认的ssh-代理,我可以在Gnome的“OpenSSH密钥”下看到“密码和密钥”应用程序中列出的密钥。
使用从ssh-keygen
9.0p1便携源代码编译的OpenSSH,我可以看到公钥将标志设置为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.0p1SSH客户端具有相同的行为,因此我假设这种消息的缺失是由我的设置中的某种原因造成的。
将一些调试代码添加到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
进程。
发布于 2022-06-08 06:04:30
这更多的是一种解决办法,而不是正确的答案,但是它提供了一种修复行为的方法。有多种因素(sic!)对此:
首先,Ubuntu中有一个东西是自动将~/.ssh
目录中的键添加到登录时开始的ssh-agent
中--一旦我使用ssh-keygen
创建了一个密钥,该键就会自动出现在ssh-add -l
的输出中。它可能不是ssh本身,因为我在我的AddKeysToAgent
(或全局配置)中没有设置~/.ssh/config
,而且这个指令的默认值是no
。
为了克服这种行为,我在不同的位置(~/altssh
)生成了关键文件。
接下来,ssh更喜欢存储在ssh-agent中的密钥,因此也需要使用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.
不过,我认为这是OpenSSH中ssh-agent通信方式的一个限制。此外,也许Ubuntu不应该将sk
键添加到ssh代理作为第二级解决方案。
https://stackoverflow.com/questions/72545585
复制相似问题