.ssh/config 中的 SSH 隧道,第二条路径上有 public 密钥

SSH tunnel in .ssh/config with public key on second leg

我想通过 Ubuntu20.04 服务器 U2 访问 Ubuntu20.04 服务器 U1,因为 U1 在防火墙后面,从装有 BugSur 的 MacBook。从 U2 到 U1 的 SSH 是使用 public 密钥完成的,没有密码。我使用密码进入 U2,但下一步总是要求输入密码(我现在不记得了)。我在 MacBook 的 .ssh/config:

中见过 并尝试过这样的事情
Host U2
    HostName accessible.uni.com
    User me
    # PreferredAuthentications publickey
    ForwardX11 yes

Host U1
    HostName behind_firewall.uni.com
    User me
    # PreferredAuthentications publickey
    # IdentityFile /home/me/.ssh/id_rsa.pub
    ProxyJump U2
    ForwardX11 yes

和 运行 ssh U1 输入 U2 的密码,但随后被要求输入 U1 的密码。我怎样才能让它在第二个 ssh 上免密码工作?

您可以使用远程命令。成功连接到 U2 后,它将执行命令 ssh U1.

Host U1
    HostName accessible.uni.com
    User me
    # PreferredAuthentications publickey
    ForwardX11 yes
    RemoteCommand ssh U1

显然,在这种情况下,ProxyJump 隧道的每一段都希望通过来自 MacBook 的密钥(或密码)进行身份验证。因此,使用此选项需要制作一个 public 密钥并将其添加到每台计算机的 authorized_keys 中,它应该通过无密码传递。