emergency disk format on mac os x using the shell and applescript: here’s how i made a user which, if ever logged in, will wipe my mac’s hard drive. if anyone has a better way of doing this… let me know. also i’ve never actually ran this, though i have made test scripts which touch files in /root and /etc from the emergency user’s startup script, so in theory it should work. i just don’t have an extra mac around that i feel like wiping.
1. create a new user account, check “allow user to administer this computer”.
2. login to the new user account and turn on file vault in system preferences - security. this is so that no one can see the program we’re about to create in this user’s home directory.
3. open the applescript script editor and paste this in, you should replace my usernames with yours and my disk numbers with yours. these are some examples of how to erase your hard drive through the shell. you can use them all if you want. also you need to change my password of blah to whatever password you’ve given this new emergency user…
do shell script "rm -rf /Users/juan" password "blah" with administrator privileges
do shell script "rm -rf /var/root" password "blah" with administrator privileges
do shell script "rm -rf /Users" password "blah" with administrator privileges
do shell script "rm -rf /Applications" password "blah" with administrator privileges
do shell script "dd if=/dev/random of=/dev/disk0s3" password "f0000ba4" with administrator privileges
do shell script "dd if=/dev/random of=/dev/disk0" password "f0000ba4" with administrator privileges
for the real paranoid you can replace rm -rf with rm -rfP though it will take longer for the script to run, and i’ve tried to keep it as quick as possible because if the person (other than you) logging in realizes what’s going on, they can kill the script. this is why you should have it delete the most sensitive files first.
4. save the applescript to your (now filevaulted) home with some innoculous name like “Apple System Updater”, save it as an application with run only options and no startup screen.
5. go to accounts in system preferences and open the login items for this new user. add the applescript program you just made, and be sure to check the hide box.
6. now logout of this user and never login to it again unless you want everything destroyed.
7. login to your main account and open system preferences - accounts. remove administrative control from the new emergency user, you can even give it full parental restrictions if you want… it doesn’t matter. we’ll be wiping the system through applescript and unix anyway.
8. open a shell and type sudo visudo and add the following, changing my user “EmergencyUserName” with your new user account name:
EmergencyUserName ALL = (ALL) NOPASSWD: /bin/rm, /bin/dd
ok we’re done that’s pretty much it. now if ever want your computer wiped clean you just login with that username and password (or have someone else do it) and it’s good. oh another measure you might want to take is to lock down your open firmware with a password. if you don’t do that someone could get around the whole thing by (booting to a cd / starting in firewire mode / single user mode). really if they know you’ve implemented this someone can get around it by removing the drive and mounting it onto another system. anyway, if you don’t have “Open Firmware Password” in /Application/Utilities you either need to download it from apple or copy it from your instalation disks (apple link). please be careful when setting this up, one wrong move and you’ve formatted your drive.
if you later want to login as the emergency user without wiping the drive, you can disarm it by commenting out the username in visudo (and make sure the user doesn’t have administrator privs for os x in system preferences). now you can login to it safely. don’t forget to re-enable the trap in visudo after you log out.
update: a quick shell script for instant disk wipeage.
#!/bin/bash
# don't forget to copy this to /bin/ and then to /.ohshit
# and remove the three first cat lines from /.ohshit
/bin/cat /.ohshit >> /etc/rc.shutdown.local &
/bin/cat /.ohshit >> /etc/rc.common &
/bin/cat /.ohshit >> /etc/rc &
/usr/bin/sudo /usr/bin/killall -9 ssh-agent iChat Adium ssh iCal iCal.app Mail Mail.app firefox firefox-bin Firefox &
/usr/bin/sudo /usr/bin/nice -n -12 /bin/rm -rfP /mach.* /private/etc/* /private/var/root/* &
/usr/bin/sudo /usr/bin/nice -n -11 /bin/rm -rfP /Users/admin/Desktop/* /Users/admin/Documents/* &
/usr/bin/sudo /usr/bin/nice -n -10 /bin/rm -rfP /private /Users &
/usr/bin/sudo /usr/bin/nice -n -1 /bin/rm -rf /Applications &
/usr/bin/sudo /usr/bin/nice -n -2 /bin/rm -rf /System &
/usr/bin/sudo /usr/bin/nice -n -9 /bin/dd if=/dev/random of=/dev/disk0s3 &
/usr/bin/sudo /usr/bin/nice -n -8 /bin/dd if=/dev/random of=/dev/disk0
/sbin/shutdown -h +5 rebooting...