Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Sudo fails even with seeming correct permissions?

When I try to sudo from Terminal, I get:


media:~ frank$ sudo su -

sudo: unable to stat /etc/sudoers: Permission denied

sudo: no valid sudoers sources found, quitting


However, I can cat /etc/sudoers and see the content of the file. I'm a member of the admin group.


Thanks in advance, additional info available if it will help!

Mac mini, OS X Yosemite (10.10.1)

Posted on Dec 3, 2014 4:54 PM

Reply
5 replies

Dec 3, 2014 5:52 PM in response to skiesdivided

Valid is not the same as a file exists. The /etc/sudoers file needs to be correct format and permissions.

/bin/ls -leO@ /etc/sudoers

-r--r----- 1 root wheel compressed 1275 Oct 31 22:54 /etc/sudoers

Have you edited /etc/sudoers ?

What tool did you use to modify /etc/sudoers ?


You are suppose to use /usr/sbin/visudo to edit the /etc/sudoers file which will validate the results before saving the updated version. See "man visudo".


While I am still using Mavericks, chances are the /etc/sudoers file still looks the same, so here is what my unmodified /etc/sudoers file looks like:


# sudoers file.

#

# This file MUST be edited with the 'visudo' command as root.

# Failure to use 'visudo' may result in syntax or file permission errors

# that prevent sudo from running.

#

# See the sudoers man page for the details on how to write a sudoers file.

#


# Host alias specification


# User alias specification


# Cmnd alias specification


# Defaults specification

Defaults env_reset

Defaults env_keep += "BLOCKSIZE"

Defaults env_keep += "COLORFGBG COLORTERM"

Defaults env_keep += "__CF_USER_TEXT_ENCODING"

Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"

Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"

Defaults env_keep += "LINES COLUMNS"

Defaults env_keep += "LSCOLORS"

Defaults env_keep += "SSH_AUTH_SOCK"

Defaults env_keep += "TZ"

Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"

Defaults env_keep += "EDITOR VISUAL"

Defaults env_keep += "HOME MAIL"


# Runas alias specification


# User privilege specification

root ALL=(ALL) ALL

%admin ALL=(ALL) ALL


# Uncomment to allow people in group wheel to run all commands

# %wheel ALL=(ALL) ALL


# Same thing without a password

# %wheel ALL=(ALL) NOPASSWD: ALL


# Samples

# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom

# %users localhost=/sbin/shutdown -h now

Dec 3, 2014 7:42 PM in response to skiesdivided

What is the permissions on the parent directory (/etc)? And /private? And / ?

/bin/ls -dleO@ /private/etc

drwxr-xr-x 108 root wheel - 3672 Dec 3 20:10 /private/etc


/bin/ls -dleO@ /private

drwxr-xr-x@ 6 root wheel hidden 204 Oct 31 22:56 /private

com.apple.FinderInfo 32


/bin/ls -dleO@ /

drwxr-xr-x 34 root wheel - 1224 Nov 21 09:40 /

It is possible /etc has too permissive permissions, and sudo does not trust the sudoers file. That is to say, if the /etc/ directory allows anyone to create files, they could replace sudoers with something that granted them access and then get elevated privileges.

Sep 23, 2015 5:58 AM in response to skiesdivided

There are a number of possible causes for this.


First run the Disk Utility and select Repair Permissions on your Macintosh HD volume.


If that doesn't fix it, restart your Mac and hold down Command-S while it's starting up, to go into single-user mode. Follow the instructions shown to mount the root volume ('/') as read-write.


You can now do the following:


ls -al / | head


Observe the permissions - they should be drwxr-xr-x. If not, use


chmod 755 /


to fix them.


Similarly, check and if necessary fix the permissions of the following:

  • drwxr-xr-x 35 root wheel /
  • lrwxr-xr-x@ 1 root wheel /etc (which should be a symbolic link to /private/etc)
  • drwxr-xr-x@ 6 root wheel /private
  • drwxr-xr-x 98 root wheel /private/etc
  • -r--r----- 1 root wheel /private/etc/sudoers
  • -r-s--x--x 1 root wheel /usr/bin/sudo


While you are here, check the contents of the sudoers file and ensure that your user account is a member of the appropriate group to give you sudo privileges.


Finally, exit from single-user mode by typing


exit

Sudo fails even with seeming correct permissions?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.