AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 628619
Accepted
Znarkus
Znarkus
Asked: 2014-09-16 07:20:00 +0800 CST2014-09-16 07:20:00 +0800 CST 2014-09-16 07:20:00 +0800 CST

sudo 没有密码问题

  • 772

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,但没有奏效。

sudo
  • 2 2 个回答
  • 8272 Views

2 个回答

  • Voted
  1. MadHatter
    2014-09-17T00:57:17+08:002014-09-17T00:57:17+08:00

    你给PATH二进制错误。输出显示which它是/usr/sbin/service,但您继续/usr/bin/service在sudoers条目中指定。

    尝试

    forge   ALL=(ALL)     NOPASSWD: /usr/sbin/service
    
    • 2
  2. Best Answer
    alexus
    2014-09-16T07:22:19+08:002014-09-16T07:22:19+08:00

    尝试以下操作:

    /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
    $ 
    
    • 1

相关问题

  • 为什么 su 到 root 而不是以 root 身份登录?

  • Firefox 执行从具有权限删除的根执行脚本失败

  • scp 后 sudo 到超级用户

  • 如何使用 sudo 在系统配置文件中添加行?

  • 为什么 sudo 命令需要很长时间才能执行?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve