Ubuntu SFTP性能优化方法
sudo apt update && sudo apt upgrade,确保Ubuntu内核、OpenSSH等软件为最新版本,获取性能改进与安全补丁。systemctl disable/uninstall关闭未使用的服务(如FTP、Telnet、蓝牙),减少系统资源占用。Subsystem sftp internal-sftp(替代传统的sftp-server);AllowGroups sftpusers(仅允许指定用户组使用SFTP);PasswordAuthentication no,改用公钥认证(PubkeyAuthentication yes),提升安全性的同时减少认证开销;MaxSessions 10(每个用户的最大会话数)、MaxStartups 50:30:100(控制并发连接数上限,避免资源耗尽)。ChrootDirectory %h),减少文件系统遍历的开销,同时增强安全性。sysctl命令增大TCP接收/发送缓冲区(如net.core.rmem_max=16777216、net.core.wmem_max=16777216),提升大文件传输效率。net.ipv4.tcp_no_delay=1,减少小数据包的延迟,适合频繁的小文件传输。net.ipv4.tcp_fastopen=3,减少握手延迟,提升连接建立速度。tune2fs调整挂载选项(如noatime,避免每次访问更新访问时间)。vm.swappiness=10),减少磁盘I/O,提升文件访问速度。/etc/security/limits.conf或/etc/security/limits.d/95-sftp-limit.conf设置用户级限制(如username hard nofile 1024限制最大文件描述符数,username hard nproc 200限制最大进程数)。htop、iotop、nload等工具实时监控CPU、内存、磁盘I/O及网络流量,及时发现性能瓶颈。sshd_config中添加-l COMPRESS(如Subsystem sftp /usr/lib/openssh/sftp-server -l COMPRESS),减少大文件的传输数据量。rsync的--partial --progress --rsh=ssh选项并行传输多个文件。