This post will show you how to remove the prompt for a password when running a sudo command.
There are certain circumstances where editing the sudoers file is necessary. For example, when building a netboot image if you want some scripts to run unattended that require a sudo command you can set your sudoers file to not prompt for a password. I’ve used this in the imaging process I’ve (painfully) built for MacOS Catalina 10.15. (The asr restore command requires ‘sudo’ and I wanted the restore process to be hands off)
The sudoers file on a Linux and Unix system controls who has system rights. This allows an administrator to control who has access to system commands. When editing the sudoers file you need to be really careful, a corrupted file can lock you out of sudo privileges. This is why you should ALWAYS use the command visudo. This will prevent a corrupt sudoers file from being saved. You can use any text editor to write to the file but it won’t check for correct formatting unless you use visudo.
Back to actually editing the file…
When you run the command sudo visudo scroll down till you find this section
# root and users in group wheel can run anything on any machine as any user root ALL = (ALL) ALL %admin ALL = (ALL) ALL
There are a few options here. You can allow the root user, administrators, or individual users to run sudo commands without a password.
To add an individual user you would add this line below that section.
username ALL = (ALL) NOPASSWD: ALL
Or for the root user and all admin users, this is what you’d want to do
# root and users in group wheel can run anything on any machine as any user root ALL = (ALL) NOPASSWD: ALL %admin ALL = (ALL) NOPASSWD: ALL
DISCLAIMER: There are serious security risks with allowing any users to run sudo commands without a password prompt. Unix is built with security in mind and this is a great security measure that should only be bypassed if you know what you are doing.