Sudo password doesn’t work even if I have no password

passwordsudoterminal

I've erased the password from preferencenow I can log in without using any password but when I run a sudocommand terminal ask me a password if I insert nothing or the old one it return error. What's happen?

Best Answer

sudo requires a password by default on Mac OS X.

Apple's knowledge base article explains more, Mac OS X: sudo command requires a non-blank admin password:

In Mac OS X v10.5 through 10.5.8, if you press the Return key at the password prompt without entering a password (even if the user has no password, which is not recommended), the command entered will not execute and you will be returned to a command prompt.

In Mac OS X v10.6 or later, if you press the Return key at the password prompt without entering a password, the message "Sorry, try again." will be displayed and you will be prompted for a password again.

If your administrator account has no password (a blank password), you must give that user a password before using the sudo command.

If you must remove the need for a password to use sudo, you can edit the /etc/sudoers file using visudo command. A thread on macoshints discusses how:

Use the visudo command as root.

Look for the line:

%admin ALL=(ALL) ALL

Change it to:

%admin ALL=(ALL) NOPASSWD: ALL

Requiring a password is highly recommended. Removing this check reduces the security of your Mac and exposes your computer to attack or abuse.