Monday, March 31, 2008

How to fix a major OSX permissions blunder...

...or, "Ow, the stupid - it hurts"

So I'm in the Mac Terminal, about to chmod a dir to 600... simple enough: $ sudo chmod -R 600 foo/bar ... and I accidently fat-finger "space slash" at the end: $ sudo chmod -R 600 foo/bar /

Silly me doesn't even realize it till I try "ls" next...

$ ls
ls: command not found

Sweet. baby. jesus.

Can't even shut down the machine... I don't have permissions! It's just hanging there until I force power-off. Now it won't boot to the gui.

Ok, no problem - I'll just boot into single-user mode and:

 $ chmod -R a+x /

Success? Nope. Machine still won't boot to a gui. Hmm... I have an external HD, let's mount it, copy my user home and reinstall! So, single-user mode... mount a USB drive... where the heck is this device? There's about fifty "tty*" in /dev, none named like the sparse help I found on Google.

Ok, Plan C: rsync what I need out to another server! Genius! Uh, wait, "interface en0 does not exist"

Plan D: screw it, let's just reinstall. While I'm about to start the install, I notice that the Airport icon is up in the menu bar... oh, joy! Plan C revisited! I think I'll try to scp one file to start with:

$ scp /convoluted/path/to/that/file me@myserver.com:file
bash: scp: command not found

Crap. Plan E:

$ /convoluted/path/to/original/fs/usr/bin/scp

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
          [-l limit] [-o ssh_option] [-P port] [-S program]
          [[user@]host1:]file1 [...] [[user@]host2:]file2

Eureka! It still executes! So then:

$ /convoluted/path/to/original/fs/usr/bin/scp /convoluted/path/to/that/file me@myserver.com:file
bash: /usr/bin/ssh: command not found

Double crap. Aargh! Hold on a second... Airport works in install mode, so maybe USB? Pretty please?? Open up Disk Utility... yes!

Finally, I'm able to copy my user folder out to the external drive.

So the answer to "How do I undo my stupid chmod mistake?" My answer is, I didn't, I just reinstalled ;-P But it might help someone to know that internet and USB connectivity can be had via the install disc if you ever get yourself into this situation.