Linux 下 SFTP 传输慢 的原因通常可以归为以下几类,按出现频率从高到低说明,并给出对应排查/优化思路。
排查
ping 目标IP
mtr 目标IP
iperf3 -c 目标IP
优化
SFTP 基于 TCP + SSH,高 RTT 会严重限制单连接吞吐
现象
优化
默认可能使用较安全的算法,但性能差
查看当前算法
sftp -v user@host
优化(客户端)
sftp -o Ciphers=aes128-gcm@openssh.com \
-o MACs=umac-64@openssh.com user@host
服务端 /etc/ssh/sshd_config
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com
优化
tar czf - dir | ssh user@host "tar xzf -"
rsyncrsync -avzP dir/ user@host:/path/
排查
iostat -x 1
iotop
优化
临时调整
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
SFTP 每个文件都有开销
优化
某些客户端会做校验,拖慢速度
# /etc/ssh/sshd_config
UseDNS no
✅ 大文件 / 批量:
rsync -avzP
✅ 极慢网络:
tar cz | ssh
✅ 调优:
如果你愿意,可以告诉我:
我可以直接帮你给出最优方案。