在 Ubuntu 上提升 SFTP 传输速度,可以从网络、SSH/SFTP 配置、磁盘、并发方式几个层面来优化。下面按实用程度给你总结一套方法。
确认瓶颈在哪里
# 看 CPU
top
# 看磁盘 IO
iostat -x 1
# 看网络
iftop
使用有线网络 / 万兆网卡
编辑:
sudo vim /etc/ssh/sshd_config
推荐参数:
# 使用更快的加密算法
Ciphers chacha20-poly1305@openssh.com,aes128-gcm@openssh.com,aes256-gcm@openssh.com
# 启用压缩(仅低速网络有用,局域网建议关)
Compression no
# 提高吞吐量
TCPKeepAlive yes
重启:
sudo systemctl restart ssh
客户端也可加:
sftp -o Ciphers=chacha20-poly1305@openssh.com user@host
sudo vim /etc/sysctl.conf
添加:
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_window_scaling = 1
生效:
sudo sysctl -p
scp 或 rsync 更快SFTP 本身有协议开销:
rsync -avP file user@host:/path
scp -C file user@host:/path
SFTP 是单连接,小文件极慢。
✅ 方法一:parallel sftp
parallel -j 8 sftp user@host:/remote/{} ::: file1 file2 file3
✅ 方法二:tar 打包再传
tar czf - dir | ssh user@host "cd /path && tar xzf -"
如果 SFTP 仍慢:
| 场景 | 建议 |
|---|---|
| 内网大文件 | rsync + aes-gcm |
| 公网大文件 | chacha20 |
| 小文件多 | tar 打包 |
| CPU 高 | 换加密算法 |
| 网络未满 | 调 TCP 窗口 |
如果你愿意,可以告诉我:
我可以直接给你最优配置方案。