Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 have a NOPASSWD line in /etc/sudoers (edited with visudo)

gatoatigrado    ALL=(ALL) NOPASSWD: /bin/set-slow-cpufreq

However, the output is,

gatoatigrado@coral:~> sudo -n /bin/set-slow-cpufreq
sudo: sorry, a password is required to run sudo

This kind of command works on an OpenSuSE machine, but not on Ubuntu 11.10. What am I doing wrong?

Note: I cannot find any relevant system log messages, e.g. via tail -f /var/log/syslog.

edit

Here is /etc/sudoers.

Defaults    env_reset

# things I've tried copying from an opensuse machine
Defaults always_set_home
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"

root    ALL=(ALL:ALL) ALL
gatoatigrado ALL=NOPASSWD: /bin/set-slow-cpufreq
%admin ALL=(ALL) ALL
%sudo   ALL=(ALL:ALL) ALL
share|improve this question
2  
Can you show the full sudoers, the order of rules is not irrelevant. – enzotib Jan 31 '12 at 5:49
up vote 49 down vote accepted

You should put that line after the line with the rule for the admin group, because, as the sudoers man page states:

   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).
share|improve this answer
    
great, thank you!! – gatoatigrado Jan 31 '12 at 19:31
3  
as an additional note, this applies to users in multiple groups as well: e.g. user is in group admin and group sudo if the rule for sudo is after admin then the rule for sudo overrides the rule for admin for the user in both groups. – Populus Sep 30 '12 at 23:49

Just ran into this too. The Ubuntu installer prompts for a non-root admin user which gets added to the group sudo. I had then manually added myself to the sudoers file using sudo visudo:

my_username ALL=(ALL:ALL) NOPASSWD:ALL

But I still have to password authenticate.

enzotib's answer is the key to what's going on. The group sudo shows up in sudoers after the entry for my username.

Rather than moving my entry below the sudo line I simply removed it and added NOPASSWD to the entry for %sudo

That seems to work.

WARNING: Always edit sudoers with visudo. Also, having another window open switched to the root user allows you to recover any mistakes you might make while changing the sudoers 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.