在Debian系统中,可以通过修改sshd_config
文件来设置SFTP传输速率限制。以下是具体步骤:
方法一:使用sshd_config
文件
-
打开
sshd_config
文件:sudo nano /etc/ssh/sshd_config
-
添加或修改以下配置项:
Match Group sftpusers
:如果你使用的是特定用户组来管理SFTP用户,可以这样写。如果没有特定用户组,可以省略Match Group
部分。ChrootDirectory %h
:将SFTP用户限制在其主目录中。ForceCommand internal-sftp
:强制使用内部SFTP命令。AllowTcpForwarding no
:禁止TCP转发。X11Forwarding no
:禁止X11转发。MaxSessions 1
:限制每个用户的会话数。MaxStartups 1:30:100
:限制同时启动的会话数。
例如:
Match Group sftpusers ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no MaxSessions 1 MaxStartups 1:30:100
-
设置传输速率限制:
Ciphers aes128-ctr,aes192-ctr,aes256-ctr
:设置加密算法。MACs hmac-sha1,hmac-sha2-256
:设置消息认证码。KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
:设置密钥交换算法。MaxSessionsPerUser 1
:限制每个用户的会话数。MaxSessions 1
:限制同时启动的会话数。
例如:
Ciphers aes128-ctr,aes192-ctr,aes256-ctr MACs hmac-sha1,hmac-sha2-256 KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1 MaxSessionsPerUser 1 MaxSessions 1
-
保存并退出编辑器:
Ctrl + X Y Enter
-
重启SSH服务:
sudo systemctl restart sshd
方法二:使用pam_limits.conf
文件
如果你希望通过PAM(Pluggable Authentication Modules)来限制SFTP用户的传输速率,可以编辑/etc/security/limits.conf
文件。
-
打开
limits.conf
文件:sudo nano /etc/security/limits.conf
-
添加以下配置项:
* hard nofile 1024 * soft nofile 640 @sftpusers hard nofile 1024 @sftpusers soft nofile 640
这里的
@sftpusers
是你的SFTP用户组名称。 -
保存并退出编辑器:
Ctrl + X Y Enter
-
重启SSH服务:
sudo systemctl restart sshd
注意事项
- 确保你的SFTP用户属于相应的用户组(例如
sftpusers
)。 - 修改配置文件后,务必重启SSH服务以使更改生效。
- 根据你的具体需求调整配置项的值。
通过以上步骤,你可以有效地限制Debian系统中SFTP用户的传输速率。