debian

Debian SFTP配置中如何设置传输速率限制

小樊
38
2025-03-28 03:48:59
栏目: 智能运维

在Debian系统中,可以通过修改sshd_config文件来设置SFTP传输速率限制。以下是具体步骤:

方法一:使用sshd_config文件

  1. 打开sshd_config文件

    sudo nano /etc/ssh/sshd_config
    
  2. 添加或修改以下配置项

    • 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
    
  3. 设置传输速率限制

    • 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
    
  4. 保存并退出编辑器

    Ctrl + X
    Y
    Enter
    
  5. 重启SSH服务

    sudo systemctl restart sshd
    

方法二:使用pam_limits.conf文件

如果你希望通过PAM(Pluggable Authentication Modules)来限制SFTP用户的传输速率,可以编辑/etc/security/limits.conf文件。

  1. 打开limits.conf文件

    sudo nano /etc/security/limits.conf
    
  2. 添加以下配置项

    *               hard    nofile          1024
    *               soft    nofile          640
    @sftpusers        hard    nofile          1024
    @sftpusers        soft    nofile          640
    

    这里的@sftpusers是你的SFTP用户组名称。

  3. 保存并退出编辑器

    Ctrl + X
    Y
    Enter
    
  4. 重启SSH服务

    sudo systemctl restart sshd
    

注意事项

通过以上步骤,你可以有效地限制Debian系统中SFTP用户的传输速率。

0
看了该问题的人还看了