1

I think I may have corrupted my sudoers file. At any rate I can no longer use the sudo command (always hangs). I've read other questions related to this topic and tried to fix (going into Recovery mode for ex) but feels like I don't know what I'm doing. Pretty sure I caused the problem by using chmod to grant permissions too widely to a folder. This is not uncommon apparently.

Running things like sudo visudo or sudo lsof -i yield:

sudo: /private/etc/sudoers.d is world writable

This is a brand new macbook M3 btw. Was working on getting nginx going, but the certbot process wrote the wretched file to a dir unexpected by the instructions I was following, and log revealed that permission was being denied to private/etc. Trying to obtain permission there with Finder and Terminal is what caused this.

UPDATE:

my /private/etc folder's permissions now seem to have been corrected, as per advice from Linc D below. But although invoking sudo no longer responds with sudoers.d is world writable, it now simply hangs. I think the problem is now with the /etc/sudoers, but the permissions on /etc seem to be messed up. Looks like this. Notice difference between it and /private/etc

enter image description here

2 Answers 2

0

Navigate to that directory in the Finder and revert the permissions as shown in this answer. You'll have to make invisible files temporarily visible by pressing the key combination shift-command-period. The permissions should be as follows:

system:   Read & Write
wheel:    Read only
everyone: Read only
11
  • Thanks. Tried to do that earlier, and should've mentioned it. But I don't even see any permissions info using Get Info on that folder. I added a pic to question that shows what I mean.
    – Alyoshak
    Commented Apr 16 at 18:47
  • Wait ... now the permissions info has showed. Glad I tried again. You can see what it looked like earlier in my pic. Ok, so I don't have a system entry. I do have 3 entries: 'wheel', 'everyone' and myself (new computer, I'm the admin). I should change myself to system using chown?
    – Alyoshak
    Commented Apr 16 at 18:51
  • The screenshot shows the etc symlink selected. You should instead select sudoers.d as mentioned in the original question.
    – Linc D.
    Commented Apr 16 at 18:54
  • 4
    It should be a symlink. Since you have no backups and don't seem to know exactly what you did, your only recourse is to reinstall the OS. I'm not sure whether that will repair all the damage, so you should first use the Finder to rename /private/etc to something like /private/etc.old. After reinstalling and rebooting, you should have a completely fresh replacement. You can then delete the old one.
    – Linc D.
    Commented Apr 16 at 20:20
  • 2
    Since this is “fresh from factory” as you describe is to just reinstall macOS. the problem here is that you don’t state what exactly you did (the command(s) you issued that got you in your predicament.
    – Allan
    Commented Apr 16 at 22:09
0

Assuming sudoers.d is the only thing that is broken:

Intel: Shutdown your Mac, hold down ⌘+s on startup until you get a full screen terminal, enter your password then enter this:

chmod -R 0440 /etc/sudoers.d
reboot

The last command will reboot your Mac.

Now, you test if sudo works again, if it does, back this system up now.

Apple Silicon:

Shutdown you Mac, start it holding down the Power button, when the startup options appear, you might have to enter your password. In there, open DiskUtility and use First Aid, it should fix permissions on your main drive.

7
  • 1
    We don‘t know whether the OP uses an Intel Mac.
    – nohillside
    Commented Apr 17 at 5:47
  • In that case, taget disk mode is maybe all that is left. Commented Apr 17 at 5:59
  • 1
    Why? Booting to recovery is also possible on Apple Silicon, just the procedure is different.
    – nohillside
    Commented Apr 17 at 6:23
  • Yeah, another is booting off a Linux USB drive. Commented Apr 17 at 7:10
  • 1
    I have an M3 Mac, apple silicon. Fwiw, I've already reinstalled my os (Sonoma) using recovery mode. See above. That restored my ability to use sudo. Thx for input, will probably help someone.
    – Alyoshak
    Commented Apr 18 at 18:22

You must log in to answer this question.

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