如何让我的 Yubikey 在 Windows 10 中使用 SSH?

问题描述

出于技术兴趣购买了 Yubikey 5 NFC(固件 5.2.7)并在可能的情况下设置了 FIDO2 身份验证后,我遇到了无法再通过 SmartGit 连接到我的 GitLab 服务器的问题,因为没有要求第二个因素因此我无法连接到服务器。

然后我决定通过 Git Bash 和 SSH 在 Windows 10 上处理它。不幸的是,这里的文档假设了很多先验知识,而我是该主题的绝对初学者。与此同时,我设法使用本地生成的 SSH 证书通过 Git Bash 和 SSH 连接到服务器。

现在我想使用 Yubikey 而不是本地存储在计算机上的证书。不幸的是,所有指令(例如这个 https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key-for-a-hardware-security-key)都会为我带来相同的错误消息:

$ ssh-keygen -t ed25519-sk -C "name@mail.com"
Generating public/private ed25519-sk key pair.
You may need to touch your authenticator to authorize key generation.
Key enrollment Failed: invalid format

在此之前,系统会提示我输入 PIN。有趣的是:消息看起来完全一样,我是否插入了 Yubikey 并不重要。使用 ecdsa-sk 的尝试导致相同的结果。

(顺便说一句。我已经在 Yubikey 上成功存储了 OpenPGP 证书。)

现在我也阅读了一些关于 libfido2 的内容,但是我找不到有关如何在 Windows 10 上使用它的任何说明。

所以我的问题是:我如何设法使用我的 Yubikey 而不是我的本地密钥? 或者:如果这是问题,我该如何安装 libfido2?

解决方法

所以:正如本月初(2021 年 5 月)在 GitHub 上宣布的那样,Security keys are now supported for SSH Git operations 是真的,但是作为 discussed here,仍然存在问题。

您的错误消息看起来像是 Debian 上正在进行的错误:“issue 980393: /usr/bin/ssh-keygen -t ecdsa-sk fails with "Key enrollment failed: invalid format"”。
它是still being reported this month

如果 -t ecdsa 也失败,请尝试使用 a plugin for OpenSSH to connect to FIDO/U2F security keys through native Windows Hello APIs 可能会有所帮助。
首先输入 export SSH_SK_HELPER=/usr/lib/ssh/ssh-sk-helper.exe,如 tavrez/openssh-sk-winhello issue 1 所示。
检查您的 OpenSSH 版本是否至少为 8.2。最新的 Windows 版 Git 站在我这边:

ssh -V
OpenSSH_8.5p1,OpenSSL 1.1.1k  25 Mar 2021