如何通过sudoers给nopasswd访问多个命令?
以下是我所知道的:
我必须在sudoers
文件中添加以下行,以便为特定任务授予用户权限。
user_name ALL=NOPASSWD: /usr/bin/apt-get install
在这种情况下,我想授予此用户访问权限以重新启动具有所有安装权限的2个服务(即Apache
和MySQL
)。
使用上面这一行,我已经给了他所有的安装权限,现在我必须再添加两行相同的权限才能获得服务的权利吗? 或者我可以在同一行添加这些命令,用逗号或其他东西分隔?
我已经通过创建一个有限管理员权限的新组来解决了这个问题…该组的名称是LimitedAdmins
之后我更新了sudoers
文件,如下所示。
附加的第一行是:
%LimitedAdmins ALL=NOPASSWD: /usr/bin/apt-get*, /etc/init.d/apache2 restart
这是完整的/etc/sudoers
文件:
# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of directly modifying his file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # 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 #includedir /etc/sudoers.d %domain_name\\administrators ALL=(ALL) ALL %LimitedAdmins ALL=NOPASSWD: /usr/bin/apt-get*, /etc/init.d/apache2 restart
如果您的系统是域或不是域,它的工作完全正常。
看起来像逗号是你需要的。
Cmnd_Alias PRINTING = / usr / sbin / lpc,/ usr / bin / lprm
…
user3 ALL =打印
资源
我最终做的是(与您正在寻找的相似):
## PRTG monitoring Cmnd_Alias PRTG = /bin/cat /proc/loadavg, /bin/df, /var/prtg/scripts/check_proc.sh prtg ALL = NOPASSWD: PRTG
内部: /etc/sudoers.d/666-prtg
(666,因为……好吧… prtg是一个基于Windows的监控工具,你知道)