无法使用内置 ssh 客户端从 macOS 通过 22 以外的任何端口 ssh 到远程主机

Aar*_*You 5 ssh networking

我最近将运行 Dropbear 的服务器上的 ssh 侦听端口从 22 切换到随机端口,以防止系统日志被某人强行淹没。

一切都很好,我可以使用 termux(一个可以安装软件包的 Android 终端模拟器)从 wan 端连接到服务器。

直到我尝试使用我的 MacBook ssh 进入服务器(在与我的手机相同的网络下,以前当 dropbear 在 22 上侦听时能够 ssh 进入服务器)。连接立即断开,ssh 向我抛出这个:

kex_exchange_identification: write: Broken pipe
Run Code Online (Sandbox Code Playgroud)

详细的输出并没有真正显示出任何有用的东西(而且我可以突然添加):

OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/my_username/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to remote.yhaoquan.top port 2123.
debug1: Connection established.
debug1: identity file /Users/my_username/.ssh/id_rsa type 0
debug1: identity file /Users/my_username/.ssh/id_rsa-cert type -1
debug1: identity file /Users/my_username/.ssh/id_dsa type -1
debug1: identity file /Users/my_username/.ssh/id_dsa-cert type -1
debug1: identity file /Users/my_username/.ssh/id_ecdsa type -1
debug1: identity file /Users/my_username/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/my_username/.ssh/id_ed25519 type -1
debug1: identity file /Users/my_username/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/my_username/.ssh/id_xmss type -1
debug1: identity file /Users/my_username/.ssh/id_xmss-cert type -1
kex_exchange_identification: write: Broken pipe
Run Code Online (Sandbox Code Playgroud)

Telnet 到 2123 端口显示我实际上成功地建立了与服务器的连接:

>telnet {hostname} 2123
Trying {host IP address}...
Connected to {hostname}
Escape character is '^]'.
SSH-2.0-dropbear
|

??]J044??d????curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,kexguess2@matt.ucc.asn.aursa-sha2-256,ssh-rsa3chacha20-poly1305@openssh.com,aes128-ctr,aes256-ctr3chacha20-poly1305@openssh.com,aes128-ctr,aes256-ctrhmac-sha1,hmac-sha2-256hmac-sha1,hmac-sha2-256nonenoneM?'?Rf
Run Code Online (Sandbox Code Playgroud)

当我将服务器上的端口改回 22 时,一切又恢复正常。

有谁知道问题可能出在哪里或我应该如何诊断问题?提前致谢 :)

编辑 1: 对于遇到相同问题的人,临时解决方案是使用OpenSSH. 执行此操作的最简单方法(使其成为一个嵌入式解决方案)是使用Homebrew

kex_exchange_identification: write: Broken pipe
Run Code Online (Sandbox Code Playgroud)

此命令会将您使用的 ssh 客户端更改为/usr/bin/ssh放置在您刚刚使用 brew 安装的/usr/local/bin/ssh点的别名OpenSSH,该症状似乎没有出现。

这并没有解决这个问题,这个职位是。我仍在寻找解决方案。

小智 2

我遇到了同样的问题:ssh 在没有网络活动的情况下返回“kex_exchange_identification:写入:损坏的管道”。

就我而言,有罪的一方是 AdGuard。

我在高级配置中添加了用于 ssh 的端口,network.extension.exclude.ports,现在它可以工作了。根据您的配置,network.extension.exclude.domains 可能是更好的选择。