7

I was following a tutorial which had this command to create a launchd.conf file in /etc/

sudo echo "some command" > /etc/launchd.conf

But it wouldn't work, I got permission denied after entering my admin password. It seemed like the permissions for the link were wrong, so I did sudo chmod 755 /etc/ But now I can't load a terminal, I get the error The administrator has set your shell to an illegal value

If I tried to sudo a command now I get

sudo: can't open /private/etc/sudoers: Permission denied
sudo: no valid sudoers sources found, quitting
Process *tramp/sudo root@localhost* exited abnormally with code 1

This is what the link /etc looks like, what should it look like, and how do I restore it?

lrwxr-xr-x   1 root           wheel          11 Jul 21  2011 etc -> private/etc

/private/etc ...

drw-r--r-- 111 root           wheel    3774 Mar 26 02:25 etc

edit: I'm using Mac OS X 10.7.3

1
  • 2
    Nice one. :-P Always a better idea to elevate your own privileges than to change the permissions of your core directories. The permission denied you were getting was likely due to another problem.
    – NReilingh
    Mar 26, 2012 at 3:33

3 Answers 3

6

Kyle Jones' answer will definitely work, but have you tried running a Permissions Repair from Disk Utility? That might do the trick....

8
  • 1
    Are you sure? It did fix the problem
    – justinhj
    Mar 26, 2012 at 4:07
  • 2
    @WilliamJackson To my knowledge, it checks the filesystem's permissions against installed packages (perhaps from .pkg receipts). As /etc/ is a file installed with the core OS, I don't see why it wouldn't work.
    – NReilingh
    Mar 26, 2012 at 4:42
  • 1
    @NReilingh I should have done more research before I spouted off. I was wrong and you are correct. I trivially edited the answer so I would be able to remove my downvote. Mar 26, 2012 at 13:39
  • 4
    I also discovered that (at least in 10.7) you can find out if a file or folder will be fixed with Repair Disk Permissions by running this command in Terminal: pkgutil --file-info /etc, replacing /etc with any location you want to check. Of course that is not much help when you can't load Terminal. Mar 26, 2012 at 13:40
  • 1
    @IgorG. Since this answer was written, Apple has removed permissions repair since it is no longer necessary, thanks to SIP. It was previously found in Disk Utility.
    – NReilingh
    Apr 12, 2016 at 15:20
10

Reboot your Mac, holding down command-s when you first hear the boot chime. Keep holding it down until you start seeing text on the screen. The system will boot into single user mode with a root shell.

mount -uw /
chmod a+x private/etc

will make /etc accessible again. Type exit to the shell and the Mac will finish booting.

6
  • Don't you have to mount the fs first?
    – slhck
    Mar 26, 2012 at 5:37
  • private/etc is on the root partition.
    – Kyle Jones
    Mar 26, 2012 at 5:42
  • 2
    The root partition is mounted readonly in single-user mode. You have to remount it for write access (mount -uw /) in order for the chmod command to work. Mar 26, 2012 at 17:20
  • 1
    @Gordon Indeed. Thanks for pointing that out. I've edited the answer to include the needed mount command.
    – Kyle Jones
    Mar 26, 2012 at 18:07
  • 1
    Upvote for the solution but also wanted to add that, in my case, it was the root that had the wrong permissions. So chmod a+x / worked for me. Thanks!
    – RARay
    Nov 9, 2012 at 17:17
-1

Permissions and ownership of /etc and /private/etc seem both correct to me; by the way, you forgot to also check /private, which could also have wrong permissions.

I had exactly the same issue and in my case the permissions of the root folder itself got corrupted. What people overlook is that / is in fact also a real, normal directory and just like every directory it has ownership and permissions. Ownership should be root:wheel and permission should be 755 (that's rwxr-xr-x).

The easiest way to restore both was starting Script Editor and then typing and running that script:

do shell script "/usr/sbin/chown root:wheel /" with administrator privileges
do shell script "/bin/chmod 755 /" with administrator privileges

You are prompted for amdin password and then chown and chmod come to the rescue. After that sudo was working again.

2
  • The permissions aren't correct. x flag is needed to enter a folder. Jan 12, 2017 at 3:18
  • @ivan_pozdeev 755 sets the X-flag for all users, 755 means rwxr-x-r-x: permissions-calculator.org/decode/755 and of course everyone needs permission to access / as otherwise you have access to nothing (as all files/folders, all mounted drives, yes even all devices are subfolders of / and you don't have access to them without the X flag)
    – Mecki
    Jan 12, 2017 at 12:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .