macOS Catalina 上的 SSH ProxyJump 无法正常工作

Hen*_*rik 4 ssh proxy openssh macos macos-catalina

我有 3 台电脑:
1. 我的 macOS Catalina mac
2. 我的第一个 Raspberry Pi
3. 我的第二个 Raspberry Pi

在我的 Mac 上,ssh 运行版本:OpenSSH_8.1p1、OpenSSL 1.1.1d 2019 年 9 月 10 日

我可以通过 ssh 分别登录每个树莓派。

我想通过跳过第一个 Pi 从我的 mac 到第二个 Pi。像这样:

+-------+       +--------+       +--------+
|  Mac  | ----> | raspi1 | ----> | raspi2 |
+-------+       +--------+       +--------+
Run Code Online (Sandbox Code Playgroud)

使用这个 .ssh/config 文件:

Host 1pi
    HostName raspi1
    User pi
    #IdentityFile ~/.ssh/id_ed25519

Host 2pi
    HostName raspi2
    User pi
    ProxyJump 1pi
    #IdentityFile ~/.ssh/id_ed25519
Run Code Online (Sandbox Code Playgroud)

虽然我能够登录第一个 Raspberry Pi,但在尝试登录第二个 Raspberry Pi 时总是遇到相同的错误。

$ ssh 2pi
kex_exchange_identification: banner line contains invalid characters
Run Code Online (Sandbox Code Playgroud)

我什至尝试过使用 IdentityFile 参数并仅使用 -J 选项。但结果还是一样。

$ ssh -J pi@raspi1 pi@raspi2
kex_exchange_identification: banner line contains invalid characters
Run Code Online (Sandbox Code Playgroud)

我在 macOS Mojave 上尝试过,效果很好。我在 Linux 上尝试过并且成功了。

如何让它在 macOS Catalina 上运行?如何跳到第 1 个 Pi 上的第 2 个 Pi?

当我这样做时,ssh 2pi -vv我得到这个(以及其他调试信息)

debug2: channel_input_open_confirmation: channel 0: callback start
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 2097152 rmax 32768
debug1: kex_exchange_identification: banner line 0: \033[H\033[2JSSH-2.0-OpenSSH_7.9p1 Raspbian-10+deb10u1
kex_exchange_identification: banner line contains invalid characters
debug1: channel 0: free: direct-tcpip: listening port 0 for raspi2 port 22, connect from 127.0.0.1 port 65535 to UNKNOWN port 65536, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Killed by signal 1.
Run Code Online (Sandbox Code Playgroud)

Dan*_*kle 5

OpenSSH_8.1p1 有一个错误,它交换了%n%h。因为ProxyJump本质上使用的是ProxyCommand ssh -W %h:%p,它实际上是发送Host名称而不是HostName1pi而不是raspi1)。

如果您不想跳过安装 OpenSSH_8.2p1 或其他任何内容的麻烦,您可以替换ProxyJump 1piProxyCommand ssh -W %n:%p 1pi,直到 Apple 替换 OpenSSH 的版本。考虑到 Apple 是报告该错误的人(感谢 Pierre-Olivier),我假设它将在下一个 10.15.4 Beta 中更新。

如果您对源代码感兴趣,请在此处引入该错误:https://github.com/openssh/openssh-portable/commit/fbe24b142915331ceb2a3a76be3dc5b6d204fddf#diff-5bfa45f3fb322e569a8101399c9c551cR1372

该错误已在这里修复:https://github.com/openssh/openssh-portable/commit/2ab335712d084d9ccaf3f53afc3fa9535329da87#diff-5bfa45f3fb322e569a8101399c9c551cR1395


作为上述答案的替代方案,一个可能更简单的答案将解决您的问题,并且在 Apple 发布修复程序时不会让您更改任何内容。

只需添加2pi到您的/etc/hosts文件中即可raspi1。例如{IP address of 2pi} 2pi。假设您的 IP 地址是 192.168.1.10,则为:

echo "192.168.1.10 2pi" | sudo tee -a /etc/hosts
Run Code Online (Sandbox Code Playgroud)