在 Ubuntu 上 SFTP 传输慢 通常由网络、SSH 配置、磁盘 IO 或加密算法等因素引起。下面按常见原因 → 对应解决办法给你一个系统排查清单。
ping 目标IP
iperf3 -c 目标IP
如果 iperf3 本身就慢 → 网络问题,不是 SFTP 问题
编辑:
sudo vim /etc/ssh/sshd_config
确保或添加以下内容:
# 禁用 DNS 反查(非常重要)
UseDNS no
# 保持连接
TCPKeepAlive yes
# 提高吞吐量
ClientAliveInterval 60
ClientAliveCountMax 3
重启 SSH:
sudo systemctl restart ssh
SFTP 基于 SSH,加密算法很影响速度
在客户端连接时指定:
sftp -oCiphers=aes128-gcm@openssh.com -oMACs=umac-128@openssh.com user@host
或写入客户端配置:
vim ~/.ssh/config
Host *
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com
MACs umac-128@openssh.com
小文件是 SFTP 最慢的场景
❌ 慢:
sftp> put *.log
✅ 快:
tar czf data.tar.gz dir/
sftp> put data.tar.gz
rsync -avzP ./local/ user@host:/remote/
优点:
iostat -x 1
或
sar -d 1
如果是磁盘 IO 满:
sudo sysctl -w net.ipv4.tcp_window_scaling=1
sudo sysctl -w net.core.rmem_max=16777216
sudo sysctl -w net.core.wmem_max=16777216
永久生效:
sudo vim /etc/sysctl.conf
net.ipv4.tcp_window_scaling=1
net.core.rmem_max=16777216
net.core.wmem_max=16777216
如果你只是传文件,不考虑交互:
✅ 直接用 scp / rsync
scp -C file user@host:/path
✅ 或开 HTTP 服务
python3 -m http.server 8000
✅ 关 DNS 反查
✅ 用 aes-gcm
✅ 打包小文件
✅ 用 rsync
✅ 检查磁盘 IO
✅ 调 TCP 窗口
如果你愿意,可以告诉我:
我可以给你 针对性最强的一套配置。