Add Your Account as a Sudoer on Mac
Updated: Oct 16, 2022
With great power comes great responsibility.
– Uncle Ben
-
Run
whoami. You will use this value later to replace<YOUR_ACCOUNT> -
Switch to an admin account by running
su <ADMIN_ACCOUNT> -
Run
sudo cat /etc/sudoersand verify that the following line exists somewhere in that file 1#includedir /private/etc/sudoers.d -
Use visudo 2 to create a new sudoers file 3 by running
sudo visudo -f /etc/sudoers.d/sudoers -
Press the
ikey for Insert mode, then type the following line<YOUR_ACCOUNT> ALL=(ALL) ALL -
Press
ESC, then type:xfollowed by theENTERkey to save your changes -
Verify your changes by running
sudo cat /etc/sudoers.d/sudoers -
Run
exitto logout of the admin account and return to your account -
Test your sudo access by running a simple command, such as
sudo echo "hello world"
-
On Mac,
/etcis a symlink to/private/etc↩︎ -
To learn more about this command, type
info visudointo Terminal and read up ↩︎ -
We’re creating a new sudoers file instead of editing the existing one at
/etc/sudoersbecause this is a best practice. For more info see this stackoverflow thread ↩︎