将组添加到sudoers没有任何影响

我试图授予www-data组访问sudo下的某些命令(即重新启动Apache),我没有运气。 我花了大多数星期五来看这个问题,必须看20个论坛post,SO / SF线程有关的问题,没有运气。

以下是我的sudoers文件(通过visudo编辑)。

# # This file MUST be edited with the 'visudo' command as root # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. Defaults !requiretty Defaults env_reset Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:$ # 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 # Allow members of www-data group access to apache %www-data ALL= NOPASSWD: /usr/bin/service apache2 * # See sudoers(5) for more information on "#include" directive 

如果我以我的jenkins用户身份login(这是www-data组的一部分,如下所示);

 root@ip-REDACTED:~# groups jenkins jenkins : www-data jenkins 

我无法运行“sudo service apache2 restart”,如下所示。

 jenkins@REDACTED:/root$ sudo service apache restart [sudo] password for jenkins: jenkins is not allowed to run sudo on ip-REDACTED. This incident will be reported. 

jenkins并不是sudo集团的一员,但我不希望它能够获得一切。 另外,它似乎没有采取在sudoers设置的NOPASSWD标志。 我已经尝试了所有我能想到的事情,并且空白。 值得一提的是,这是在EC2实例上运行,EC2是否对sudoers文件做了什么额外的限制?

提前致谢。

尝试使用Cmnd_Alias定义:

 Cmnd_Alias APACHE_CMD = /usr/sbin/service apache2 restart %www-data ALL = (root)NOPASSWD: APACHE_CMD 

确保service可执行文件的path正确。

您也可以检查/etc/nsswitch.conf文件中的sudoers定义,并确保它包含一个files属性:

 sudoers: files ldap sss