Skip to main content

Add your account as a sudoer on Mac

Published: 2019-04-17 • Lastmod: 2019-09-12

  1. Switch to an administrator account:

    su <administrator_account>
    
  2. Run sudo cat /etc/sudoers and verify that the following line exists somewhere in that file: 1

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

    sudo visudo -f /etc/sudoers.d/sudoers
    
  4. Press the i key for “insert” mode, then type:

    <your_account> ALL=(ALL) ALL
    
  5. Press esc, then type :x followed by the return key to save your changes

  6. Verify your changes:

    sudo cat /etc/sudoers.d/sudoers
    
  7. Type exit to logout of the administrator account and return to your account

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


Next: Mawmaw Betty's strawberry pie recipe
Previous: Check if a program exists from your bash script