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).

  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.)

  • 2
    It should use a relative link target: ln -s private/etc /Volumes/Macintosh\ HD/etc – Gordon Davisson Nov 19 '19 at 17:27
  • You are right...but the other solution works too - your solution creates the original link content (etc -> private/etc) though – klanomath Nov 19 '19 at 17:52

I believe that if you create a MacOS bootable installer (e.g., via these instructions) that you will have access to a terminal prompt. This requires that:

  • you have access to a second MacOS device (yours, a friend's, etc) on which you can create bootable media,
  • a spare USB flash drive or other removable media, and
  • sufficient knowledge to mount your hard drive manually from within the installer environment.

At that point, you should be able to replace the /etc symlink.

I don't have access to a MacOS device on which to test this right now, but I will in a couple of days. If I have the chance, I'll try to validate these instructions and update them if necessary.


Short answer:

Without sudo you can not run commands as root without entering the root user's password.

If you do know the password of the root user then run

/usr/bin/su - root -c "ln -s /private/etc /etc"

and enter the password of the root user.

  • Using su has the same issue as sudo, it won't authorize because the command can't find sudoers. – Kernel Shafters Nov 19 '19 at 4:06
  • 1
    The su command does not require /etc/sudoers (and the sudo in this command is unnecessary -- if you can run su, then you're already root and sudo is a no-op). If the you know the root password, this is probably the easiest solution, once you drop the sudo. – larsks Nov 19 '19 at 4:10

You must log in to answer this question.