12

I have an /etc/sudoers with the following:

glens   ALL=NOPASSWD:/usr/sbin/service php5-fpm
glens   ALL=(ALL:ALL) ALL

And I'm trying to run the command:

sudo /usr/sbin/service php5-fpm restart

However, I'm still prompted for my password.

This AskUbuntu question/answer suggests I have the correct syntax, but I'm still prompted.

0

1 Answer 1

22

The NOPASSWD entry should be placed beneath the other line:

glens   ALL=(ALL:ALL) ALL    
glens   ALL=NOPASSWD:/usr/sbin/service php5-fpm

From the manual (man sudoers):

When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).

Therefore your order of NOPASSWD being first will be overridden by the second line (ALL=(ALL:ALL) ALL).

3
  • I see in the manpage that this is true, changing the order doesn't seem to have any effect on being prompted for a password. Commented Nov 30, 2015 at 15:47
  • 5
    You need a * at the end of the nopasswd sudoers entry to allow sudo to match 'restart' Commented Nov 30, 2015 at 18:37
  • 3
    Or the full command glens ALL=NOPASSWD:/usr/sbin/service php5-fpm restart Commented Jun 14, 2017 at 4:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.