解决 macOS Sequoia 奇怪的SSH链接问题:kex_exchange_identification: read: Connection reset by peer

从 Sonoma 升级到 Sequoia 遇到过各种各样的SSH连接问题,其中包括但不限于
1. 防火墙问题
2. WiFi 隐私问题
3. 加密协议不匹配问题
4. SSH 版本强制 2.0 的问题

但今天又遇到一个新问题,通过SSH连接报错,提示 kex_exchange_identification: read: Connection reset by peer,看起来连接被中断,通过 Verbose Mode 查看SSH连接提示如下:

$ ssh -v [email protected]
OpenSSH_9.2p1 Debian-2+deb12u5, OpenSSL 3.0.15 3 Sep 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 10.0.1.3 [10.0.1.3] port 22.
debug1: Connection established.
debug1: identity file /home/zhaoxitao/.ssh/id_rsa type -1
debug1: identity file /home/zhaoxitao/.ssh/id_rsa-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ecdsa type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ed25519 type 3
debug1: identity file /home/zhaoxitao/.ssh/id_ed25519-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ed25519_sk type -1
debug1: identity file /home/zhaoxitao/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_xmss type -1
debug1: identity file /home/zhaoxitao/.ssh/id_xmss-cert type -1
debug1: identity file /home/zhaoxitao/.ssh/id_dsa type -1
debug1: identity file /home/zhaoxitao/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u5
kex_exchange_identification: read: Connection reset by peer
Connection reset by 10.0.1.3 port 22

通过 debug1: Connection established. 判断连接没有问题,防火墙OK,WiFi 隐私没问题。但是SSH客户端没有匹配到任何一种加密模式,开始排查加密问题,于是在 /etc/ssh/sshd_config.d/100-macos.conf 里增加了更宽泛的加密协议:

# 明确协议版本
Protocol 2

# 放宽密钥交换算法
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group-exchange-sha256

# 放宽加密算法
Ciphers aes256-ctr,aes192-ctr,aes128-ctr

# 放宽 MAC 算法
MACs hmac-sha2-512,hmac-sha2-256

重启SSH 服务测试:

sudo launchctl stop com.openssh.sshd && sudo launchctl start com.openssh.sshd

问题依旧,没有任何改变。仔细分析认为这不应该啊,我已经在配置文件指定了加密方式,不可能完全没变化,于是尝试手动开启 sshd 调试模式,看看服务端输出什么:

# 停止原服务
sudo launchctl stop com.openssh.sshd

# 前台调试模式启动
sudo /usr/sbin/sshd -d -p 22

结果报错:

 No such file at /etc/ssh/sshd_config

问题找到了,macOS 采用了 分片式 SSH 配置(类似 Ubuntu 的 sshd_config.d 目录机制),但 sshd 服务仍然要求存在主配置文件 /etc/ssh/sshd_config, 我的服务器上的 sshd_config.d 配置文件不知道为啥丢失了,系统bug? 那问题就简单了,重新生成一个配置文件:

# 创建主配置文件并包含分片配置
echo "Include /etc/ssh/sshd_config.d/*.conf" | sudo tee /etc/ssh/sshd_config

# 修改文件权限
sudo chmod 644 /etc/ssh/sshd_config

再次尝试开启 SSH 服务,SSH 客户端成功登录,至此问题解决。

顺便说一句,Sequoia 跑服务的问题真的很多,各种bug,看来真的要开始着手找基于 Linux 的 MDM 服务器了,macOS 真的是一点也用不了了。

Related post

  1. NO IMAGE
  2. NO IMAGE
  3. NO IMAGE
  4. NO IMAGE
  5. NO IMAGE
  6. NO IMAGE

There are no comment yet.

ABOUT

老赵的个人博客,关于 Mac, iPhone, iPad, iPod等产品的软件和硬件技术交流。也讨论Linux/UNIX技术,服务器运维技术等。

2025 年 4 月
 12345
6789101112
13141516171819
20212223242526
27282930  

Powerd by WordPress on Xserve
Xserve 2009
@2012-2024 HelloMac Copyright