在Ubuntu系统中,通过SSH限制用户权限可以通过以下几种方法实现:
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
pam_limits.conf
配置文件:编辑/etc/security/limits.conf
文件,添加以下内容:
<username> hard nofile 100
<username> soft nofile 100
将<username>
替换为要限制权限的用户名。这将限制用户的文件描述符数量。
usermod
命令:使用usermod
命令将用户的默认shell更改为受限shell,例如rbash
:
sudo usermod -s /bin/rbash <username>
将<username>
替换为要限制权限的用户名。这将限制用户只能访问其主目录,并使用受限的shell环境。
注意:这些方法可以组合使用,以实现更严格的权限限制。在进行更改之前,请确保备份相关配置文件,以防出现问题。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Ubuntu SFTP如何配置