To add an account to the list of sudoers, you'll need an administrator account.
If you simply want to make sure that your current user has sudo access AND this command works, then you already have sudo access and you're done.
sudo echo hello world
Make sure that there is an 'admin' group.
dscl . list /Users | grep -v “^_”
dscacheutil -q group -a name admin
id -un
At this point, if you just want for your user to have sudo access AND your user exists in the admin group, then you are done because all admin users have sudo access. Otherwise, continue to add the target user to the sudoers file. You will need a user with sudo access to do this.
(If your current user is not in the admin group, OR you want to add give sudo access to another user)
su <administrator_account>
(This line usually exists already, this is just a verification step)
sudo cat /etc/sudoers
#includedir /private/etc/sudoers.d
sudo visudo -f /etc/sudoers.d/sudoers
You're now in the vi editor. Here are instructions for those who don't know vi.
<your_account> ALL=(ALL) ALL
Verify your changes:
sudo cat /etc/sudoers.d/sudoers
Type exit
to logout of the administrator account and return to your account
sudo echo hello world
On Mac, /etc
is a symlink to /private/etc
Type info visudo
in Terminal for help.
It's best practice to create a new sudoers
file instead of editing the existing one at /etc/sudoers
. See this stackoverflow thread.
Sourced article: https://zwbetz.com/add-your-account-as-a-sudoer-on-mac