Accidentally deleting all OSX users using dscl

mac-osx

OK, so I just did something really stupid and deleted all the user accounts on an OSX 10.6.6 machine by running this:

sudo dscl . -delete /users

What I actually wanted to do was delete a single, troublesome account using a command like this:

sudo dscl . -delete /users/localadmin

…but I absent-mindedly pressed return too early and deleted the lot. I've tried using -list and can confirm that I have indeed wiped all the accounts. The machine is currently running fine, but I'm sure that once I log out / reboot then it will be completely broken.

I don't mind that I've deleted the normal user accounts (there was only one I wanted anyway). But it's surely going to be a big problem that system accounts like _installer and _jabber and _lda and _windowserver etc etc are gone.

So my question is, how can I restore the standard set of system accounts? Do I have to reinstall OSX from scratch? Or can I either:

  • undelete those system accounts, or
  • run some command to recreate the system accounts?

Best Answer

If this is on a Mac OS X workstation install (as opposed to Mac OS X Server), you could download the "Server Admin" tools from Apple and use "Workgroup Manager" to first export the standard set of accounts from a working system and then import them into the system that's missing those accounts.

This may have been misleading. You can do the same procedure whether or not it's Mac OS X or Mac OS X Server you're dealing with. It's just that for server, the tools are already there and for the workstation OS, you'll need to download them.