Add your account as a sudoer on Mac
Published: 2019-04-17 • Last updated: 2019-09-12
-
Switch to an administrator account:
su <administrator_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 3sudo visudo -f /etc/sudoers.d/sudoers
-
Press the
i
key for “insert” mode, then type:<your_account> ALL=(ALL) ALL
-
Press
esc
, then type:x
followed by thereturn
key to save your changes -
Verify your changes:
sudo cat /etc/sudoers.d/sudoers
-
Type
exit
to logout of the administrator 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 ↩︎