sudo没有在某些命令上工作

Debian 8上sudo有一个相当奇怪的问题:用户不能执行/etc/sudoers.d中的一些命令。 我使用Chef来分发configuration,所有的文件都是自动生成的。

例:

这个configuration工作正常

root@server:~# cat /etc/sudoers.d/nginx # This file is managed by Chef. # Do NOT modify this file directly. user ALL=(root) NOPASSWD:/usr/sbin/nginx 

这失败了:

 root@server:~# cat /etc/sudoers.d/update-rc.d # This file is managed by Chef. # Do NOT modify this file directly. user ALL=(root) NOPASSWD:/usr/sbin/update-rc.d user@www42:~$ sudo update-rc.d [sudo] password for user: Sorry, user user is not allowed to execute '/usr/sbin/update-rc.d' as root on server. 

什么可能是错的?

诊断:

 Mar 5 12:12:51 server sudo: user : command not allowed ; TTY=pts/0 ; PWD=/home/user ; USER=root ; COMMAND=/usr/sbin/update-rc.d Mar 5 12:14:25 www42 su[1209]: pam_unix(su:session): session closed for user user root@server:~# sudo --version Sudo version 1.8.10p3 Configure options: --prefix=/usr -v --with-all-insults --with-pam --with-fqdn --with-logging=syslog --with-logfac=authpriv --with-env-editor --with-editor=/usr/bin/editor --with-timeout=15 --with-password-timeout=0 --with-passprompt=[sudo] password for %p: --disable-root-mailer --with-sendmail=/usr/sbin/sendmail --with-rundir=/var/lib/sudo --mandir=/usr/share/man --libexecdir=/usr/lib/sudo --with-sssd --with-sssd-lib=/usr/lib/x86_64-linux-gnu --with-selinux --with-linux-audit Sudoers policy plugin version 1.8.10p3 Sudoers file grammar version 43 

问题是update-rc.d的点(在/etc/sudoers.d/update-rc.d )。 从man sudo

#includedir指令可用于创buildsudo.d目录,系统软件包pipe理器可以将sudoers规则作为软件包安装的一部分放入。 例如,给出:

 #includedir /etc/sudoers.d 

sudo将读取/etc/sudoers.d中的每个文件, 跳过以〜结尾的文件名包含a。 字符以避免导致包pipe理器或编辑器临时/备份文件出现问题。

尝试并运行sudo -ll以获取适用于您的用户的命令/ config的列表。

如果(看起来是这样的话)你的update-rc.d子句没有出现,你可以考虑调整你的厨师食谱来为每个用户部署一个sudoers.d文件,而不是几个。

您也可以考虑是否可以保证与群组相关的sudoers文件。

这个问题的答案可能有所帮助: https : //askubuntu.com/questions/246455/how-to-give-nopasswd-access-to-multiple-commands-via-sudoers