MacOS – Deleted symlink to /etc and now missing sudoers

macossudo

I messed up bad, real bad.

I accidentally deleted the symbolic link to my /etc directory. Now I can't create another one because I keep getting an error:

$ sudo ln -s /private/etc /etc
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

Any help would be appreciated, thanks.

Output of ls -l /etc:

$ ls -l /etc
ls: /etc: No such file or directory

My /etc was symlinked to /private/etc (sudoers is in there).

Best Answer

  1. Boot to Recovery Mode (cmd-R)
  2. Open Terminal from the menubar Utilities > Terminal
  3. Soft-link /private/etc to /etc on your main Volume:

    ln -s private/etc /Volumes/Macintosh\ HD/etc 
    

    Replace Macintosh\ HD with the name of your main volume (if your forgot it, just enter df or ls /Volumes/ and check for its name! Don't forget to escape blanks with a backslash.)