Execute sudo without a Password

If you use terminal often, then you must face an annoying problem: you need to enter the password everytime when you want superuser access with the command sudo. So there is a way to solve it without sharing the root user access: add the user you log in as to the wheel group.

  • Know the user account you are logging: execute id in terminal to show the account info:

id-command

The "aldora" at the "uid=501(aldora)" tells you the account name.

  • Execute "sudo visudo", and press arrow down key to scroll down until you see the following line:
    sudo-visudo
    The lines mean that root user and any user in "admin" group can run any command. If you look again at the output of id command, you can see the account is already assigned in the group "admin".
  • If your account is not in the group, you can add it via the command:
// example: sudo usermod -a -G admin aldora
sudo usermod -a -G <group name> <your account name>
  • Disable password requirement: press "i" to enter interactive mode to change config. Below the above lines, add the following config:
# enable user <account name> to gain superuser access without password
<account name> ALL=(ALL) NOPASSWD:ALL

Replace "account name" with the account name you get from id command, for example: aldora ALL=(ALL) NOPASSWD:ALL

  • Press "Esc" to exit the editor mode, and press colon with "shift" + ":", then press "x" to save and exit. Now, your account can gain superuser access without typing the password.