Add Your Account as a Sudoer on Mac

Published: Apr 17, 2019
Updated: Oct 16, 2022

With great power comes great responsibility.

– Uncle Ben

  1. Run whoami. You will use this value later to replace <YOUR_ACCOUNT>

  2. Switch to an admin account by running

  3. Run sudo cat /etc/sudoers and verify that the following line exists somewhere in that file 1

     #includedir /private/etc/sudoers.d
  4. Use visudo 2 to create a new sudoers file 3 by running

     sudo visudo -f /etc/sudoers.d/sudoers
  5. Press the i key for Insert mode, then type the following line

  6. Press ESC, then type :x followed by the ENTER key to save your changes

  7. Verify your changes by running

     sudo cat /etc/sudoers.d/sudoers
  8. Run exit to logout of the admin account and return to your account

  9. Test your sudo access by running a simple command, such as

     sudo echo "hello world"

  1. On Mac, /etc is a symlink to /private/etc ↩︎

  2. To learn more about this command, type info visudo into Terminal and read up ↩︎

  3. 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 ↩︎