txw*_*ger 37 ssh ssh-agent gnupg
我可以使用 ssh 配置文件启用转发添加到 ssh-agent 的 ssh 密钥。我怎样才能对 gpg 密钥做同样的事情?
Bri*_*ton 20
OpenSSH 的新 Unix Domain Socket Forwarding 可以从 6.7 版开始直接执行此操作。
您应该能够执行以下操作:
ssh -R /home/bminton/.gnupg/S.gpg-agent:/home/bminton/.gnupg/S-gpg-agent -o "StreamLocalBindUnlink=yes" -l bminton 192.168.1.9
Run Code Online (Sandbox Code Playgroud)
b0f*_*0fh 18
编辑:这个答案已经过时了,因为 OpenSSH 中已经实现了适当的支持,请参阅 Brian Minton 的答案。
SSH 只能在隧道内转发 tcp 连接。
但是,您可以使用类似socat通过 TCP 中继 unix 套接字的程序,使用类似的程序(您将在客户端和服务器主机上都需要 socat):
# Get the path of gpg-agent socket:
GPG_SOCK=$(echo "$GPG_AGENT_INFO" | cut -d: -f1)
# Forward some local tcp socket to the agent
(while true; do
socat TCP-LISTEN:12345,bind=127.0.0.1 UNIX-CONNECT:$GPG_SOCK;
done) &
# Connect to the remote host via ssh, forwarding the TCP port
ssh -R12345:localhost:12345 host.example.com
# (On the remote host)
(while true; do
socat UNIX-LISTEN:$HOME/.gnupg/S.gpg-agent,unlink-close,unlink-early TCP4:localhost:12345;
done) &
Run Code Online (Sandbox Code Playgroud)
测试它是否适用于gpg-connect-agent. 确保远程主机上的 GPG_AGENT_INFO 未定义,以便它回退到$HOME/.gnupg/S.gpg-agent套接字。
现在希望您所需要的只是一种自动运行所有这些的方法!
小智 11
在新版本的 GnuPG 或 Linux 发行版中,套接字的路径可以改变。这些可以通过
$ gpgconf --list-dirs agent-extra-socket
Run Code Online (Sandbox Code Playgroud)
和
$ gpgconf --list-dirs agent-socket
Run Code Online (Sandbox Code Playgroud)
然后将这些路径添加到您的 SSH 配置中:
Host remote
RemoteForward <remote socket> <local socket>
Run Code Online (Sandbox Code Playgroud)
复制公钥的快速解决方案:
scp .gnupg/pubring.kbx remote:~/.gnupg/
Run Code Online (Sandbox Code Playgroud)
在远程机器上,激活 GPG 代理:
echo use-agent >> ~/.gnupg/gpg.conf
Run Code Online (Sandbox Code Playgroud)
在远程机器上,还要修改 SSH 服务器配置并添加此参数(/etc/ssh/sshd_config):
StreamLocalBindUnlink yes
Run Code Online (Sandbox Code Playgroud)
重新启动 SSH 服务器,重新连接到远程机器 - 然后它应该可以工作了。