Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I did it adding the following line, but doesn't work (at least in my case):

username ALL=(ALL) NOPASSWD:/sbin/shutdown -h now

then making a launcher in the desktop with the following instruction:

sudo shutdown -h now

When I tried it, keeps asking me the password. What am I doing wrong?

PS: I'm using visudo

share|improve this question
2  
Try executing sudo /sbin/shutdown -h now (note the full path just like in /etc/sudoers). –  Philipp Wendler Aug 13 '12 at 6:08
    
I tried just now, but keeps asking the password. I'm using Lucid Lynx and adding the line in the following section of the sudoers file: #User privilege specification –  blackedx Aug 13 '12 at 6:51
    
Just to be sure, you put your real user name in that line (in place of username)? Lines starting with # are comments and are irrelevant. –  Philipp Wendler Aug 13 '12 at 6:53
    
Yes, I'm putting my real username. before ALL=(ALL) NOPASSWD:/sbin/shutdown -h now About the section of the sudoers file, I know that # are comments but, Can I add the line in any section of the file and it should work? –  blackedx Aug 13 '12 at 7:02
    
The sudoers file does not have sections, it is just a list of lines. –  Philipp Wendler Aug 13 '12 at 7:07

1 Answer 1

up vote 2 down vote accepted

The order of lines in /etc/sudoers is important.

The man page says:

   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).

So, if you have the following usual line in your /etc/sudoers file

%admin ALL=(ALL) ALL

and your user is part of the admin group, you need to put the line in your question behind that line. Otherwise it will never be used, because the line for %admin will always match instead.

In general, put the most specific lines (like those for single users and commands) at the end of the file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.