Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.