2

I've modified (in some wrong way) the file etc/sudoers in my Mac OS X 10.6.8.

For this reason I've erased the wrong line and replaced the original file. But now whenever I type sudo commands the output is:

sudo: /etc/sudoers is owned by uid 501, should be 0
Segmentation fault

A solution could be this but when I type su (and the password) the output is:

su: Sorry

How can I fix this problem?

Baduel
  • 531
  • 3
  • 12
  • 30

4 Answers4

7

For the record, there is an easier way to fix this on OS X: run Disk Utility, select the volume in the sidebar, then the First Aid tab, and click Repair Disk Permissions. /etc/sudoers is one of the system files it knows the "correct" permissions for, so it'll take care of it for you.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
  • Thank you for your answer. This tool take a lot of time (22 minutes in my case) but it has found a lot of errors, so +1 =) – Baduel Nov 06 '11 at 01:55
  • Usually, the problems permissions repair finds don't really matter; but just occasionally it'll fix something nasty (like this). p.s. thanks @Bavarious. – Gordon Davisson Nov 06 '11 at 06:37
2

I've followed these steps to enabling and using the "root" user in Mac OS X.

In this way I can use the fix posted in my question.

Baduel
  • 531
  • 3
  • 12
  • 30
  • once root user is enabled. you can use su root to login as root rather than sudo as root – Hesky Dec 03 '13 at 02:11
1

Try sudo -u root vim /etc/sudoers , replacing 'root' with the user that you were logged in as when originally modifying /etc/sudoers. Then make any needed changes, save and quit, and try again.

I ran into this issue when adding source ~/.bash_profile to my ~/.bashrc file while logged in as root. Running sudo -u root vim ~/.bashrc as a non-root user and deleting the source ~/.bash_profile line fixed my issue.

Tyler Dane
  • 951
  • 1
  • 14
  • 25
  • I mistakenly added `source ~/.bashrc` to `/etc/bashrc`. With `sudo -u root vim /etc/bashrc` and removing the `source` line, the issue is fixed. Thanks @Ty Hitzeman. – vijay v Nov 01 '20 at 06:57
1

You'll need to login as root directly, or boot into a root console, in order to change the ownership of the /etc/sudoers file.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • The same way you login in as any other user. (If you have automatic login and no manual login method, you'll have to boot into a `root` console.) – David Schwartz Nov 05 '11 at 18:05
  • @Macmade if I type `su` I've the problem in the question. David, How can I boot into a `root` console? – Baduel Nov 05 '11 at 18:09
  • [Boot into single user mode](http://support.apple.com/kb/HT1492) then [make the filesystems writable](http://apple.stackexchange.com/questions/14484/mac-wont-boot-way-to-mount-drive-and-delete-one-file/14485#14485). – David Schwartz Nov 05 '11 at 18:11
  • Ok after I boot on single user mode I type ’mount -o update /’ but the system returns: unknown flag '-o' – Baduel Nov 05 '11 at 18:30
  • `/sbin/mount` is not recognized as an internal or external command, etc. – Baduel Nov 05 '11 at 18:42
  • Thank you David, I've solved in [this way](http://support.apple.com/kb/ht1528) to use `su` command. +1 =) – Baduel Nov 05 '11 at 20:29