CentOS 下 SSH 传输慢,常见原因和对应“破法”如下,按见效快慢排序:
SSH 默认会做反向 DNS 查询,网络不好时非常慢。
服务端(CentOS 上)
sudo vi /etc/ssh/sshd_config
改成:
UseDNS no
重启:
sudo systemctl restart sshd
客户端
ssh -o GSSAPIAuthentication=no user@host
或写入 ~/.ssh/config:
Host *
GSSAPIAuthentication no
sudo vi /etc/ssh/sshd_config
GSSAPIAuthentication no
重启 sshd。
ssh -o ControlMaster=auto -o ControlPath=/tmp/%r@%h:%p -o ControlPersist=10m user@host
或写进 ~/.ssh/config:
Host *
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
ControlPersist 30m
scp / rsync 而不是 ssh 管道✅ 推荐:
rsync -avzP file user@host:/path
❌ 慢:
cat file | ssh user@host "cat > file"
老机器/虚拟机特别明显。
测试:
ssh -c aes128-gcm@openssh.com user@host
写入配置:
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com
ping -M do -s 1472 host
如果丢包 → 调 MTU 或查链路。
scp → rsyncbbcp / aria2c / lftpnc + tarssh -vvv user@host
看卡在哪一步:
expecting SSH2_MSG_KEX → 算法/CPUtrying authorized_keys → DNS/GSSAPI如果你能贴:
我可以直接给你一套精确配置。