在CentOS系统中,通过修改SSH配置文件(通常位于/etc/ssh/sshd_config)可以设置SFTP传输速率
sudo vi /etc/ssh/sshd_config
Match Group sftp_users
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
MaxSessions 10
MaxStartups 10:30:60
Ciphers aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha2-256
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
ControlMaster auto
ControlPath /tmp/ssh_mux_%r@%h:%p
ControlPersist 1h
这里的配置项解释如下:
Match Group sftp_users:仅对名为sftp_users的用户组应用以下设置。ChrootDirectory %h:将用户的根目录限制在其主目录中。ForceCommand internal-sftp:强制使用内部SFTP服务器。AllowTcpForwarding no 和 X11Forwarding no:禁用TCP和X11转发。MaxSessions 10:限制每个用户最多同时打开10个SFTP会话。MaxStartups 10:30:60:限制每分钟最多允许10个新的SFTP连接请求。Ciphers、MACs 和 KexAlgorithms:设置加密算法、消息认证码和密钥交换算法。ControlMaster auto、ControlPath 和 ControlPersist:设置SSH连接复用。保存并关闭文件。
重启SSH服务以应用更改:
sudo systemctl restart sshd
sftp_users的用户组,并将需要限制速率的用户添加到该组:sudo groupadd sftp_users
sudo usermod -aG sftp_users your_username
将your_username替换为实际的用户名。
sudo passwd your_username
按照提示输入新密码。
现在,您已经成功设置了CentOS系统中SFTP用户的传输速率。请注意,这些设置仅适用于使用SFTP的用户。对于使用SCP或其他传输方式的用户,您需要在其他地方进行配置。