Linux 下 SFTP 传输慢一般由网络、加密、磁盘、配置或客户端方式导致。可以按下面思路逐步排查和优化。
# SFTP
sftp user@host
> get bigfile
# SCP
scp user@host:/path/bigfile .
# 裸网络速度(非加密)
iperf3 -c host
iperf3 很快,但 SFTP 慢 → SSH/SFTP 层面问题iperf3 也慢 → 网络问题默认加密对 CPU 压力大。
/etc/ssh/ssh_config 或 ~/.ssh/configCiphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com
重启 SSH:
systemctl restart sshd
Host *
ControlMaster auto
ControlPath ~/.ssh/%r@%h-%p
ControlPersist 10m
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
sysctl -w net.ipv4.tcp_wmem="4096 65536 16777216"
写入 /etc/sysctl.conf 永久生效。
❌ 慢:
sftp> mget *
✅ 快:
tar czf - dir | ssh user@host "tar xzf -"
或
scp -r dir user@host:/path
| 工具 | 说明 |
|---|---|
rsync |
断点续传、增量 |
lftp |
支持多线程 |
bbcp |
超高性能 |
rclone |
云/对象存储 |
示例(rsync):
rsync -avz --progress dir/ user@host:/path/
SFTP 慢也可能是:
iostat -x 1
%util 高 → 磁盘瓶颈✅ 网络是否正常
✅ 是否小文件太多
✅ 是否 CPU 被加密吃满
✅ 是否磁盘 IO 满
✅ 是否跨地域/公网
如果你愿意,可以告诉我:
我可以直接给你一套最优配置。