在CentOS系统中,您可以使用cgroups(控制组)来限制SFTP用户的带宽使用。以下是设置步骤:
cgroup-tools软件包:sudo yum install cgroup-tools
sftp_bandwidth:sudo cgcreate -g net_cls:/sftp_bandwidth
1:10:echo 10 | sudo tee /sys/fs/cgroup/net_cls/sftp_bandwidth/net_cls.classid
echo 100000 | sudo tee /sys/fs/cgroup/net_cls/sftp_bandwidth/net_cls.limit_in_bytes
id <username>
将<username>替换为您要限制带宽的SFTP用户名。记下UID,例如1001。
echo <UID> | sudo tee /sys/fs/cgroup/net_cls/sftp_bandwidth/tasks
将<UID>替换为您在上一步找到的SFTP用户的UID。
/etc/ssh/sshd_config文件:sudo vi /etc/ssh/sshd_config
在文件末尾添加以下内容:
Match Group sftp_bandwidth
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
这将限制属于sftp_bandwidth组的用户在SFTP会话中的带宽。
sudo systemctl restart sshd
现在,属于sftp_bandwidth组的SFTP用户的带宽应受到限制。请注意,这些更改可能需要重新启动系统才能生效。