温馨提示×

ubuntu ssh传输慢怎么破

小樊
69
2026-09-25 07:35:47
栏目: 智能运维

Ubuntu 下 SSH 传输慢,通常和网络、SSH 配置、加密算法、DNS有关。下面按“最常见 → 进阶”给你一套排查和优化方案,基本能解决 90% 的情况。


一、先确认慢在哪(很重要)

time scp file user@host:/tmp/

或

ssh user@host "echo ok"
  • 连接慢(登录前卡) → DNS / GSSAPI
  • 传输慢(登录后传文件慢) → 加密 / 网络 / 磁盘

二、SSH 登录慢(连接阶段)

1️⃣ 关闭 DNS 反向解析(最常见)

服务端 /etc/ssh/sshd_config:

UseDNS no
GSSAPIAuthentication no

然后:

sudo systemctl restart ssh

客户端也可加:

GSSAPIAuthentication no

2️⃣ 使用 IP 而非域名

ssh user@192.168.1.10

避免 DNS 解析卡顿。


三、传输速度慢(数据阶段)

3️⃣ 换更快的加密算法

默认 aes-256-gcm 不一定最快。

测试:

scp -c aes128-gcm@openssh.com file user@host:/tmp/

或服务器端:

Ciphers aes128-gcm@openssh.com,chacha20-poly1305@openssh.com

4️⃣ 提高 SSH 吞吐量

客户端 ~/.ssh/config:

Host *
    Compression no
    TCPKeepAlive yes

如果是高延迟网络:

Host *
    IPQoS throughput

5️⃣ 不用 SSH,用更快的工具(强烈推荐)

如果你只是传文件:

rsync(增量 + 快)

rsync -avP file user@host:/path/

tar + ssh(目录超快)

tar czf - dir | ssh user@host "cd /tmp && tar xzf -"

四、网络层问题

6️⃣ MTU / 网卡问题

ip link show

尝试:

sudo ifconfig eth0 mtu 1400

7️⃣ 检查丢包

ping host
mtr host

五、虚拟化 / 云服务器特别注意

  • 云厂商限速(带宽上限)
  • virtio 网卡驱动
  • 跨地域传输必然慢

六、终极方案(不依赖 SSH)

  • sftp 也慢 → 直接 nc
# 接收端
nc -l 1234 > file

# 发送端
nc host 1234 < file

快速总结(推荐你直接做)

✅ UseDNS no
✅ GSSAPIAuthentication no
✅ 用 rsync
✅ 换 aes128-gcm
✅ 用 IP 不用域名


如果你愿意,可以告诉我:

  • Ubuntu 版本
  • 是内网还是公网
  • 是scp / rsync / git / 什么场景慢

我可以直接给你一套最优配置。

0 踩