How to Reset Leopard Back to the Setup Assistant

This is being included here as a relink from the following post:

http://hints.macworld.com/article.php?story=2007110800450816

This hint will probably be most useful for folks who configure machines for a living, but if you’re selling or giving away your machine, or just troubleshooting login issues, it may come in handy. Here are the Terminal commands to delete a temporary (or lone) account in single-user mode on Leopard (in the following commands, replace username with whatever account short name you’ve created). Note that this must all be done in single user mode (hold Command-S during boot).

First, the usual stuff:

$ mount -uw /
$ rm -R /Library/Preferences/
$ rm -R /Users/username/

(Note that deleting /Library/Preferences/ is optional and in some cases may cause problems after pre-configuring some third-party software. However, I do this after simple configs or installs, e.g., install an OS, apply Software Updates, and then give it to the end user to create a fresh account.)

Now here’s what’s new in Leopard:

$ rm /var/db/dslocal/nodes/Default/users/username.plist
$ rm /var/db/.AppleSetupDone

While getting rid of .AppleSetupDone wasn’t really necessary for OSes 10.2 thru 10.4, you do have to get rid of the Setup flag file in Leopard, or when you reboot, you’ll get a login window and no working account to log in with.

I was hoping that I might be able to just type dscl . -delete /Users/temp to axe the account info (much shorter and easier to remember), but apparently the dscl command doesn’t work in single-user mode even when you follow the instructional prompt to start Local Directory Services — oh well.

BTW, trying to do all this through the GUI is pretty much impossible. Even if you enable Root and log in as that, the Accounts prefpane in Leopard won’t let you delete the last or only Admin user account.

I also discovered something interesting: if you give your temporary account (or any Admin account) no password, you’ll find that when you boot up and try to run sudo from a shell (bash at least), it won’t work — it just dumps back to the main user prompt. Solve this by giving your temporary account a short password, unless you’re sure that you won’t have to do any superuser shenanigans from Terminal as part of the config. A good security hedge for end users who don’t like passwords, but still a new wrinkle to deal with.