温馨提示×

Ubuntu SSH如何限制用户权限

小樊
41
2025-03-02 05:36:26
栏目: 智能运维
Ubuntu服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Ubuntu系统中,通过SSH限制用户权限可以通过以下几种方法实现:

  1. 使用sshd_config配置文件:

编辑/etc/ssh/sshd_config文件,找到或添加以下内容:

Match User <username>
    ForceCommand internal-sftp
    PasswordAuthentication yes
    ChrootDirectory /home/<username>
    AllowTcpForwarding no
    X11Forwarding no

<username>替换为要限制权限的用户名。这将限制用户只能使用SFTP,并将其根目录更改为指定的目录。同时,禁止TCP和X11转发。

保存文件并重启SSH服务:

sudo systemctl restart ssh
  1. 使用pam_limits.conf配置文件:

编辑/etc/security/limits.conf文件,添加以下内容:

<username> hard nofile 100
<username> soft nofile 100

<username>替换为要限制权限的用户名。这将限制用户的文件描述符数量。

  1. 使用usermod命令:

使用usermod命令将用户的默认shell更改为受限shell,例如rbash

sudo usermod -s /bin/rbash <username>

<username>替换为要限制权限的用户名。这将限制用户只能访问其主目录,并使用受限的shell环境。

注意:这些方法可以组合使用,以实现更严格的权限限制。在进行更改之前,请确保备份相关配置文件,以防出现问题。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Ubuntu SFTP如何配置

0