MENU

Yubikey 新手使用指南

前几天 Cloudfalreyubikey 推出了合作活动,使用优惠代码购买 yubikey 只要很低价格就能购买。之前没玩过 yubikey,所以决定体验下 yubikey的使用方法。

macOS 使用 yubikey 登陆

20221008220549.png

  • 点击 Application下的 PIV
    20221008221200.png

首次请点击 PIN Management -> Configure PINs->Current PINs右侧的 Use default PINs` -> 设置密码。
同样的方法更改 PUK。

20221008221414.png

然后点击 Manage Key -> 右侧的 Generate -> 然后勾选 Protect with PIN

20221008221657.png

完成后,点击 Application -> PIV 旁边的 Setup for macOS

20221008222407.png

然后根据指示操作就好了.

让 macOS 仅使用 yubikey 登陆

此操作存在危险!!!确认安全后再开启!!!

参考链接

在终端中输入以下命令:

sudo defaults write /Library/Preferences/com.apple.security.smartcard enforceSmartCard -bool true

macOS 使用 yubikey 来认证 ssh 登陆

安装 Brew.

略。

安装环境

brew install gnupg
brew install ykman

生成密钥

运行:

gpg --card-edit
>admin
>generate

编辑 ~/.gnupg/gpg-agent.conf只需加入下列一段

enable-ssh-support

此时仍无法导出 ssh-key

$ ssh-add -L
The agent has no identities.

编辑 ~/.zshrc或者 ~/.bashrc

export GPG_TTY="$(tty)"
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

重新打开终端
检查 ssh-add -L 是否工作并导出公钥

ssh 连接出错 sign_and_send_pubkey: signing failed: agent refused operation

可能是 GPG_TTY 设置错误。
检查环境下 有无以下参数

GPG_TTY=$(tty)
export GPG_TTY

也有可能未更新 TTY,终端下输入

gpg-connect-agent updatestartuptty /bye

另外一种解决方法

编辑 ~/.zshrc或者 ~/.bashrc

alias ssh="gpg-connect-agent updatestartuptty /bye > /dev/null; ssh"
alias scp="gpg-connect-agent updatestartuptty /bye > /dev/null; scp"

Github参考链接

需要触摸才能认证

每当尝试使用 YubiKey 进行 ssh 身份验证时,如果要求触摸一下才能继续,可以防止流氓进程在插入密钥时使用它。

你可以使用YubiKey Manager CLI

安装后,使用 ykman openpgp touch 子命令配置触摸设置:

ykman openpgp set-touch aut on
ykman openpgp set-touch enc on
ykman openpgp set-touch sig on

Google 使用 yubikey

https://support.google.com/accounts/answer/6103523

Microsoft 帐户使用 yubikey

https://support.microsoft.com/en-us/account-billing/how-to-use-two-step-verification-with-your-microsoft-account-c7910146-672f-01e9-50a0-93b4585e7eb4

Windows 使用 yubikey

https://support.microsoft.com/en-us/windows/sign-in-to-your-microsoft-account-with-windows-hello-or-a-security-key-800a8c01-6b61-49f5-0660-c2159bea4d84

下载 yubikey manager

链接地址: Yubikey 官网

Last Modified: October 10, 2022