提升 Ubuntu 上 SFTP 传输速度 可以从 网络、SSH/SFTP 配置、磁盘、加密算法、客户端参数 等多个方面入手。下面按实用程度给你一套完整优化方案。
在优化前,先判断是 网络 / CPU / 磁盘 哪一块拖慢了速度:
# 查看 CPU 是否打满
top
# 查看磁盘 IO
iostat -x 1
# 查看实时网速
iftop
编辑:
sudo nano /etc/ssh/sshd_config
# 使用更快的加密算法
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
# 启用压缩(局域网不推荐,公网可尝试)
Compression no
# 提高 SFTP 性能
Subsystem sftp internal-sftp -l INFO
# 减少 DNS 查询
UseDNS no
# 增加连接复用
ClientAliveInterval 30
ClientAliveCountMax 3
然后重启 SSH:
sudo systemctl restart sshd
ssh -Q cipher
✅ aes128-gcm(CPU 占用低,速度快)
✅ chacha20-poly1305(ARM / 低功耗 CPU 更好)
sftp -c aes128-gcm@openssh.com user@server
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
验证:
lsmod | grep bbr
sudo nano /etc/sysctl.conf
添加:
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
生效:
sudo sysctl -p
-o 参数优化sftp -o Ciphers=aes128-gcm@openssh.com \
-o Compression=no \
user@server
SFTP 是 单连接、串行传输,速度天然受限。
✅ 推荐替代方案:
| 工具 | 特点 |
|---|---|
| rsync | 断点续传、增量同步 |
| lftp | 多线程 SFTP |
| rclone | 高速、并发 |
rsync -avz --progress -e ssh /local/path/ user@server:/remote/path/
# 查看磁盘类型
lsblk -d -o name,rota
# rota=1 机械盘,0 SSD
mount -t tmpfs tmpfs /mnt/ramdisk
❌ 不要开启压缩在高速网络
压缩反而消耗 CPU,降低速度
❌ 不要使用弱加密
如 arcfour(已废弃)
❌ 不要指望 SFTP 跑满 10Gbps
原生 SFTP 单线程,极限通常 100–500MB/s
| 场景 | 速度 |
|---|---|
| 默认 SFTP | 30–80 MB/s |
| 优化加密 + BBR | 80–200 MB/s |
| rsync over SSH | 100–300 MB/s |
| lftp 多线程 | 200–600 MB/s |
你可以告诉我:
我可以给你 一套针对你环境的精确参数配置。