Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I accidentally made a mistake and made my sudo commands passwordless on my Mac. How can I get it back to default?

share|improve this question

4 Answers 4

From man sudoers:

NOPASSWD and PASSWD

By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag.

You either added the NOPASSWD tag or enabled an entry with a NOPASSWD tag.

In any case, edit /etc/sudoers with command visudo (which needs sudo) and remove or comment out the entry.

For example, with these entries I can run any command without being asked for a password:

jaume   ALL=(ALL) NOPASSWD: ALL
%localaccounts  ALL=(ALL) NOPASSWD: ALL

%localaccounts means group localaccounts, of which I'm a member:

$ id
uid=501(jaume) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts)

On the other hand, if the entry lacks NOPASSWD I must authenticate:

jaume   ALL=(ALL) ALL
%staff  ALL=(ALL) ALL

You can have both behaviors with an entry like this:

jaume   ALL=(ALL) ALL,NOPASSWD:/usr/sbin/softwareupdate

Here I need to authenticate for any command except for softwareupdate.

share|improve this answer

You can edit the sudoers file to make sudo require a password again. You need to edit this file using the sudo visudo command in a terminal session and removing the line:

%sudo ALL=NOPASSWD: ALL

which is probably near the end of the file. Then save (write) the file and quit. The visudo command verifies the new file and "installs" it. You may need to restart or at least logoff and on to have this take place.

Note that the visudo command puts you in the vi editor so you need to know a little about using vi to make the changes.

share|improve this answer
    
Thanks, but I was unable to locate %sudo ALL=NOPASSWD:ALL when I edited the file. The only one I saw that was kind of the same was %wheel ALL=(ALL) NOPASSWD: ALL –  Anonymous Nov 24 '12 at 15:09
    
@Anonymous: Open Terminal and run id as shown above in my answer. If wheel is one of the groups shown that's the entry to comment out. –  jaume Nov 24 '12 at 17:08
    
t@Anonymous: Sorry that my answer wasn't on the mark. If you look at the sudoers file description (man sudoers) you'll see more info about it than you'll ever want to see (which is my best excuse). As jaume added in his comment, f the %wheel line is the only one with NOPASSWD then that should be removed or better commented out(i upvoted his answer); if there are other lines with the NOPASSWD you might want to get more advice as to which is causing this issue for you. –  Zhora Nov 24 '12 at 21:14

Look in /etc/sudoers for 'NOPASSWD:' and remove it. If you're game, try running this in a terminal window:
"sed -i 's/ NOPASSWD://g'" You can test it without the -i switch first if you want.

share|improve this answer
    
It says Permission Denied –  Anonymous Nov 24 '12 at 15:19
    
Sorry, since it is a system file you need to run the command as root or use sudo: sudo sed -i 's/ NOPASSWD://g –  Justin Nov 27 '12 at 11:57

Does your account have root/sudoer privs?

If so, try:

sudo -i

And then

passwd

That puts you into super user mode based on your account, and then resets the root password (which may do what you need since you said the visudo file sounds about right.).

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.