How to fix /etc/ folder on Mac OS X

7

1

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

justinhj

Posted 2012-03-26T02:46:00.053

Reputation: 1 162

2Nice 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 – 2012-03-26T03:33:41.907

Answers

6

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

NReilingh

Posted 2012-03-26T02:46:00.053

Reputation: 5 539

What in the world is Permissions Repair?? I cannot find it. – IgorGanapolsky – 2016-04-12T15:18:38.633

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 – 2016-04-12T15:20:20.553

This is not what Repair Permissions is for. – William Jackson – 2012-03-26T03:36:46.363

1Are you sure? It did fix the problem – justinhj – 2012-03-26T04:07:17.463

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 – 2012-03-26T04:42:45.253

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. – William Jackson – 2012-03-26T13:39:06.733

4I 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. – William Jackson – 2012-03-26T13:40:23.800

This is a very handy feature, I'm glad it is there to help after I shoot myself in the foot :) – justinhj – 2012-03-26T21:37:29.810

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.

Kyle Jones

Posted 2012-03-26T02:46:00.053

Reputation: 5 706

For google/posterity's sake.. This seems to have solved my issues with sudo: unable to stat /etc/sudoers: Permission denied (albeit without having to restart ) – mralexgray – 2015-02-23T14:38:01.470

Don't you have to mount the fs first? – slhck – 2012-03-26T05:37:54.717

private/etc is on the root partition. – Kyle Jones – 2012-03-26T05:42:45.163

2The 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. – Gordon Davisson – 2012-03-26T17:20:31.813

1@Gordon Indeed. Thanks for pointing that out. I've edited the answer to include the needed mount command. – Kyle Jones – 2012-03-26T18:07:19.720

1Upvote 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 – 2012-11-09T17:17:09.767

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

Mecki

Posted 2012-03-26T02:46:00.053

Reputation: 244

The permissions aren't correct. x flag is needed to enter a folder. – ivan_pozdeev – 2017-01-12T03:18:42.623

@ivan_pozdeev 755 sets the X-flag for all users, 755 means rwxr-x-r-x: http://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 – 2017-01-12T12:29:19.513