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/sudoers
and 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
i
key for Insert mode, then type the following line<YOUR_ACCOUNT> ALL=(ALL) ALL
-
Press
ESC
, then type:x
followed by theENTER
key to save your changes -
Verify your changes by running
sudo cat /etc/sudoers.d/sudoers
-
Run
exit
to 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,
/etc
is a symlink to/private/etc
↩︎ -
To learn more about this command, type
info visudo
into Terminal and read up ↩︎ -
We’re creating a new sudoers file instead of editing the existing one at
/etc/sudoers
because this is a best practice. For more info see this stackoverflow thread ↩︎