How to fix /etc/ folder on Mac OS X

15,639

Solution 1

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

Solution 2

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.

Share:
15,639

Related videos on Youtube

justinhj
Author by

justinhj

Updated on September 18, 2022

Comments

  • justinhj
    justinhj almost 2 years

    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

    • NReilingh
      NReilingh over 12 years
      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.
  • William Jackson
    William Jackson over 12 years
    This is not what Repair Permissions is for.
  • justinhj
    justinhj over 12 years
    Are you sure? It did fix the problem
  • NReilingh
    NReilingh over 12 years
    @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.
  • slhck
    slhck over 12 years
    Don't you have to mount the fs first?
  • Kyle Jones
    Kyle Jones over 12 years
    private/etc is on the root partition.
  • William Jackson
    William Jackson over 12 years
    @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
    William Jackson over 12 years
    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.
  • Gordon Davisson
    Gordon Davisson over 12 years
    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.
  • Kyle Jones
    Kyle Jones over 12 years
    @Gordon Indeed. Thanks for pointing that out. I've edited the answer to include the needed mount command.
  • justinhj
    justinhj over 12 years
    This is a very handy feature, I'm glad it is there to help after I shoot myself in the foot :)
  • RARay
    RARay over 11 years
    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!
  • mralexgray
    mralexgray over 9 years
    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 😎 )
  • IgorGanapolsky
    IgorGanapolsky about 8 years
    What in the world is Permissions Repair?? I cannot find it.
  • NReilingh
    NReilingh about 8 years
    @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.
  • ivan_pozdeev
    ivan_pozdeev over 7 years
    The permissions aren't correct. x flag is needed to enter a folder.
  • Francesco De Rosa
    Francesco De Rosa over 7 years
    @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)