利用Yubikey的OpenPGP在远程机器上签名和加密文件
About
最近在玩OpenPGP遇到一个问题,如何在远程机器上使用Yubikey的OpenPGP功能签名和加密,本地可以使用kleopatra或者用gpg命令来签名加密文件,ssh登陆到远程服务器上是没法用本地gpg usb智能卡来签名加密文件,由于这种抽象玩法比较少见,但好歹找到了解决办法。
Linux到Linux
本质上是转发 gpg-agent,unix socket对unix socket是没有什么问题的,兼容性比较好。
参考:
https://security.stackexchange.com/questions/166280/how-to-use-yubikey-through-gnupg-on-remote-server
Windows 到 Linux
windows到Linux有个大坑,引用
> https://github.com/PowerShell/Win32-OpenSSH/issues/1564
ssh 只能转发 unix socket,OpenSSH_for_Windows并没有实现,这个issue依然是Open,去搜了一圈貌似官方尚未解决这个问题。
> https://github.com/rupor-github/win-gpg-agent
不过原issue的作者提供了一个Rust写的解决方案,试了下完美解决了这个问题。
>https://github.com/BusyJay/gpg-bridge/tree/v0.1.1/src
1. 安装:gpg-bridge
cargo install -f --git https://github.com/busyjay/gpg-bridge
2. 运行
gpg-bridge.exe --extra 127.0.0.1:4321
4. 获取远程gpg-agent路径
gpgconf --list-dir agent-socket
3. 编辑配置文件
本机`vim ~/.ssh/config`添加
Host RemoteForward /run/user/1000/gnupg/S.gpg-agent 127.0.0.1:4321 ForwardAgent yes #<远程gpg-agent> <gpg-bridge监听端口>
4. 远程机器
编辑`/etc/ssh/sshd_config`添加
StreamLocalBindUnlink yes
5. 重启sshd
systemctl restart sshd
用WSL或者用usbip转发yubikey
这种办法也是一种办法,但是比第二种办法还折腾,遂没有采用。