使用 sudo 时遇到问题。作为用户,forge
我希望能够sudo service php5-fpm reload
无需输入密码即可运行。我尝试了以下所有变体。
forge ALL=NOPASSWD: /usr/bin/service php5-fpm reload
forge ALL=NOPASSWD: /usr/bin/service
forge ALL=(ALL:ALL) NOPASSWD: /usr/bin/service
forge ALL=(ALL:ALL) NOPASSWD: /usr/bin/service php5-fpm reload
但它一直要求我输入密码。尝试登录和退出。
# tail /var/log/auth.log
Sep 16 09:28:19 apps sudo: pam_unix(sudo:auth): conversation failed
Sep 16 09:28:19 apps sudo: pam_unix(sudo:auth): auth could not identify password for [forge]
这是整个文件。
#
# 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 env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
# User privilege specification
root ALL=(ALL:ALL) ALL
#forge ALL=NOPASSWD: /usr/bin/service
# 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
使用 Ubuntu 14.04.1 LTS
$ which service
/usr/sbin/service
问题:
$ sudo service
[sudo] password for forge:
这就是有效的方法。
视觉:
# Cmnd alias specification
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig/, /usr/bin/service, /usr/sbin/service
/etc/sudoers.d/forge
:
forge ALL = (ALL) NOPASSWD: SERVICES
尝试将文件内容移入forge
,visudo
但没有成功。
答案1
请尝试以下操作:
/etc/sudoers
:
# grep -B1 'Cmnd_Alias SERVICES' /etc/sudoers
## Services
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
#
/etc/sudoers.d/forge
:
# cat /etc/sudoers.d/forge
forge ALL = (ALL) NOPASSWD: SERVICES
#
测试
[forge@localhost ~]$ sudo service
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
[forge@localhost ~]$
调整正确的如果需要,路径service
可能会有所不同,具体取决于您的分布,要找到正确的路径,请运行以下命令:
$ which service
/sbin/service
$
答案2
PATH
您为二进制文件提供了错误。which
输出显示它是,但您在条目中/usr/sbin/service
继续指定。/usr/bin/service
sudoers
尝试
forge ALL=(ALL) NOPASSWD: /usr/sbin/service