I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it

osxsudo

I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?
And once you've recovered it, how do you set it to mode 0440?

Best Answer

If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :

  1. Create sudoers file in your home folder. You can find default content here sudoers
  2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).
  3. Now copy sudoers file from home folder's to /etc folder via Finder.
  4. Prompt will come asking for password.
  5. Enter correct password and you are done.

To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.

I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)

Related Question