sudo的安全策略:阻止/允许用户执行特定命令

您所在的位置:网站首页 sudo账户 sudo的安全策略:阻止/允许用户执行特定命令

sudo的安全策略:阻止/允许用户执行特定命令

2023-09-08 18:25| 来源: 网络整理| 查看: 265

应用场景

我们知道sudo用户组的用户可以使用sudo以root权限运行命令。某些应用场景可能要求对用户的sudo执行权限细分,比如可以执行部分命令,或者不能执行部分命令。这时可以通过配置sudo的默认安全策略插件sudoers来达到目的。

将用户移除sudo用户组(如果原来在的话)确认/etc/sudoers配置策略 要使用visudo来编辑,默认该文件带有描述:“This file MUST be edited with the ‘visudo’ command as root”。如果没有改动过该文件,其大致如下: # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d 编辑用户安全策略配置 在/etc/sudoers.d/目录下建立与用户同名的策略文件,比如: visudo -f /etc/sudoers.d/test #其中“test”为测试建立的用户名

比如,我们期望用户test 可以以管理员权限执行/usr/bin、/bin下的所有命令,但是不能修改其他用户密码以及kill其他用户进程,可以配置如下:

test ALL=/usr/bin/, !/usr/bin/passwd, /bin/, !/bin/kill

测试一下,会发现passwd被阻止了:

test@zzz:/home/sscm$ sudo passwd [sudo] password for test: Sorry, user test is not allowed to execute '/usr/bin/passwd' as root on zzz. test@zzz:/home/sscm$

在策略文件中配置:!/usr/bin/passwd user_name,该策略可以阻止修改特定用户的密码。也可以得知,该策略可以阻止特定参数的命令



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3