Renamed /etc folder. I can't login anymore

I did a silly thing by renaming the /etc folder. I was asked for the admin password to change the folder's name. But it's not possible to rename it back to /etc. As if my password was wrong.

I assume the association between password and username is stored in this folder. I can still change the admin's password in the system settings. But I can't login to the advanced options that expect admin rights.

Unfortunately I don't have a recent time machine backup to replace the /etc folder.

Now I'm concerned about rebooting my Mac, as I'm not sure if I'll be able to login again.

How do I fix this issue?


Solution 1:

I would try booting in single user mode (holding the Apple and S keys while rebooting), mount the hard drive (mount -uw /) and then check and rename etc as needed (there should be an alias at the root of the HD named etc pointing to /private/etc).

I would do an ls -al / and a ls -al /etc to see which directory name was changed and then fix the bad directory name with mv. Checking each directory would be important regardless of which fix you used (the one above or below).

If single user boot doesn't work, I would “Target Disk Mode” using another Mac (turn off the bad Mac, connect the two Macs with Firewire or Thunderbolt cable, start the bad Mac while holding down the T key), this will mount the bad Mac's drive as an external drive on the other Mac and you should be able to use the command line to change the name there.

Or, as someone else suggested, booting from the recovery partition.

Last resort is to reinstall the system, it should allow you to do that without wiping the drive.