Use sudo command in OSX without a password
Robert ShellDecember 03, 2016
To use the sudo command in Terminal without having to enter your password each time, follow these steps:
1. Switch user to root. (How to enable the root user in OSX)
2. Enter this command:
chmod +w /etc/sudoers
That makes the /etc/sudoers file writable. Sometimes it can be read-only.
3. Open /etc/sudoers in nano, vi, or the text editor of your choice, and add this line at the bottom:
[USERNAME] ALL=(ALL) NOPASSWD: ALL
4. Replace [USERNAME] with your OSX administrator account username (not the full account name). Example:
robert ALL=(ALL) NOPASSWD: ALL
This line informs sudo that your account can become any other user without giving a password.
5. After adding that line, save the sudoers file.
6. For security, make the file read-only again by typing this:
chmod -w /etc/sudoers
7. Close the Terminal app and then open it again. Now sudo will no longer ask you to enter a password.