0

I'm using macOS catalina 10.15.7. I recently found out i cannot run sudo anymore, tried to run sudo brew install nats-server, and got this message:

<myusername> is not in the sudoers file.  This incident will be reported.

I got my username by whoami. By running id, i see 80(admin) was listed there. Went to System Preferences -> Users & Groups, I saw my name (full name not my username) is listed under Current User as Admin, Mobile.enter image description here

Followed other posts online, i was able to find /etc/sudoers.d folder and sudoers file, and right click get Info, i added my username back to the permission list which allow me to read and write, the changes were made to both /etc/sudoers.d folder and sudoers file. enter image description here

At one point of time i was able to run sudo visudo /private/etc/sudoers and found out the line for admin was commented out, so i removed the comment to re-enable it, now the file has root and admin enabled, no other user:

root        ALL = (ALL) ALL
admin       ALL = (ALL) ALL

and at the bottom of the file, i saw:

## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d

after all these changes i still cannot run sudo:

sudo brew update
sudo: 4294967295,2416387072,32767,0,0,0,0,0,0,0: invalid value
sudo: error initializing audit plugin sudoers_audit
sudo brew update
Password:
<my username> is not in the sudoers file. This incident will be reported

is admin and my username the same user? it should be, right? do i have to add my username in /private/etc/sudoers file separately?

Update: run id -un, it shows my username run ls -l /etc/sudoers, it shows:

-r--r-----+ 1 root  wheel  1562 Jun 29 10:06 /etc/sudoers
5
  • Please add the output of id -un; ls -l /etc/sudoers to the question.
    – nohillside
    Jun 29, 2021 at 19:46
  • 2
    The entry in /etc/sudoers for the admin group should be %admin ALL=(ALL) ALL (the % means admin is a group name, not a username). But this messing with /etc/sudoers makes me nervous -- it should've had that entry already, and if you don't understand the file well, there's a significant chance you're just going to cause other problems as you try to fix this. Do you know what changed the file in the first place, and can you just restore the original? Jun 29, 2021 at 20:00
  • @GordonDavisson the sudo: error initializing audit plugin sudoers_audit error also looks kind of suspicous. Some change history for sure would help.
    – nohillside
    Jun 29, 2021 at 20:33
  • how can i get the change history? i don't remember did anything to that files at all. prob just os upgrade
    – user468587
    Jun 29, 2021 at 20:48
  • Only you know what kind of updates you've installed in the past. OS updates don't tend to break sudo.
    – nohillside
    Jun 29, 2021 at 20:54

1 Answer 1

0

The % is not a comment sign, is defines entries valid for groups. By removing it in sudoers you actually removed your own rights from it. Assuming you can still edit it, you should be able to add the % back.

If you can't edit it, see sudo: /etc/sudoers is owned by uid 501, should be 0 for alternative ways to change it.

PS: Your username is the name shown behind the red "username(Me)" part in the screenshots. You can also see it by running id -un in Terminal.

4
  • i've already added my username to the sudoers (in the screenshot), but why i still cannot sudo?
    – user468587
    Jun 29, 2021 at 19:39
  • Is your username really admin?
    – nohillside
    Jun 29, 2021 at 19:44
  • no my username is not admin
    – user468587
    Jun 29, 2021 at 20:25
  • 2
    Your edit added the user named admin, not your own username.
    – nohillside
    Jun 29, 2021 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .