Yubikey 新手使用指南

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

macOS 使用 yubikey 登陆

下载 yubikey manager 点击跳转

  • 点击 Application 下的 PIV

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

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

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

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

让 macOS 仅使用 yubikey 登陆

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

参考链接

在终端中输入以下命令:

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

macOS 使用 yubikey 来认证 ssh 登陆

参考链接1

  • 安装 Brew. 略。

  • 安装环境

1
2
brew install gnupg
brew install ykman
  • 生成密钥

运行以下命令,生成密钥对。并将公钥导入到服务器上。

1
2
3
gpg --card-edit
>admin
>generate
  • 编辑 ~/.gnupg/gpg-agent.conf 只需加入下列一段

enable-ssh-support

此时仍无法导出 ssh-key

1
2
$ ssh-add -L
The agent has no identities.
  • 编辑 ~/.zshrc 或者 ~/.bashrc
1
2
3
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 设置错误。

检查环境下 有无以下参数

1
2
GPG_TTY=$(tty)
export GPG_TTY

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

1
gpg-connect-agent updatestartuptty /bye
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
33135a60-master at 2024-03-09 15:10:22 +0000
Built with Hugo
Theme Stack designed by Jimmy