YubiKeyをOpenPGP cardとして使う
基本的に、ここの通り。若干修正してる。
Configuring a Yubikey with GPG for SSH Authentication — Edmundo Fuentes' Blog
Quick Fix for Yubikey GPG for SSH Auth issues in macOS — Edmundo Fuentes' Blog
GnuPGをインストール。
$ brew install gnupg2 gpg-agent pinentry-mac
gpg-agentの設定。
code:~/.gnupg/gpg-agent.conf
pinentry-program /usr/local/bin/pinentry
default-cache-ttl 3600
default-cache-ttl-ssh 3600
max-cache-ttl 7200
max-cache-ttl-ssh 7200
enable-ssh-support
.bash_profileとか.zprofileとか.zshrcとか適当に。
code:~/.zshrc
export LANG=en
export GPG_TTY=$(tty)
export SSH_AUTH_SOCK=${HOME}/.gnupg/S.gpg-agent.ssh
alias gpgreset='gpg-connect-agent killagent /bye; gpg-connect-agent updatestartuptty /bye; gpg-connect-agent /bye'
gpg-agentを再起動。
$ gpgreset
YubiKeyの状態チェック。
$ gpg --card-status
PINの変更。
$ gpg --change-pin
デフォルト値:
User PIN: 123456
Admin PIN: 12345678
秘密鍵の生成。
$ gpg --card-edit
gpg/card> admin
Admin commands are allowedと表示される。
gpg/card> generate
公開鍵の取得。
$ ssh-add -L
で表示されるはず。
表示されなかったら、上記の下準備を確認する。
(追記)これでいけた。
$ SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" ssh-add -L
$ ssh-add -L > ~/.ssh/yubikey_gpg.pub
これをSSHの公開鍵として利用する。