How do I remove a user via single user mode in 10.7?

Solution 1:

There are several problems with the script you posted.

Don't remove /Users/Shared - iTunes needs it and will fail on certain store and sharing operations.

dscl on Lion will still whine if you start it (it's looking for the missing plist) - even if you launch /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist as Ingmar Hupp has suggested.

I've never been one to worry about cleaning up the groups since I'm deleting user 501. The system will just add UID 501 back into the Admin and Staff groups the next time the Setup Assistant boots, so I do the following: (assume the short name of the user 501 is test)

  1. +S
  2. /sbin/mount -uw /
  3. cd /var/db/dslocal/nodes/Default/users/
  4. rm test.plist
  5. rm -rf /Users/test
  6. rm /var/db/.AppleSetupDone
  7. halt

I do use the official Users & Groups Preference Pane to delete all users except 501 and/or create the test user as 501 as needed since launchd can have jobs stuck if the users you are clearing aren't trivial users set up for simple updates as your case allows.

I would avoid saving a WiFi password or setting up WiFi outside the user account or use ethernet for your updates if you want to be fastidious about leaving as little of your settings behind (especially if the SSID/name isn't generic like Apple Network or has WEP/WPA keys).