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?
  • 2
    The standard answer for this kind of thing is to restore from your backup. – John Gardeniers Feb 21 '11 at 4:57
  • I'll take that as 'reinstall OSX then restore from backup', because to the best of my knowledge Time Machine doesn't back up things like internal system accounts. Can anyone confirm that? – gutch Feb 21 '11 at 5:33
  • @Gutch, that may well be the safest and fastest option. By the time you figure out another method the reinstall will probably be done. – John Gardeniers Feb 21 '11 at 6:25
  • 1
    Time machine isn't a system backup, IIRC, its more of a "backup your stuff*" thing. If you look at how apple say to use time machine to restore from a catastrophic failure they say you need to use a system restore disk first to install the OS then use time machine to "personalise" it with your data and apps. – Rob Moir Feb 21 '11 at 6:25
  • 1
    @Robert: by default, Time Machine backs up almost everything (including the OS, applications, etc; there are a few exceptions, like logs, caches, and such). Even if you exclude /System (and select the option to exclude other system files), it still backs up the users database in /private/var/db/dslocal/nodes/Default/users. – Gordon Davisson Feb 22 '11 at 7:29

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.

| improve this answer | |
  • +1 for a great idea — unfortunately it turns out that this can't be done. It's a Catch-22: once you've deleted all the user accounts it is no longer possible to create user accounts! OS X requires escalation to change user data, and because all administrator accounts were deleted I found I could no longer use sudo or authorise any administrator login popups. – gutch Feb 24 '11 at 7:12
  • You should still be able to startup in single-user mode, mount the filesystem read/write and then add an administrator user account via the command line. – AlanGBaker Feb 24 '11 at 22:41

The solution I went with is:

  • wipe the system disk
  • reinstall Mac OS X
  • restore my /Users files from backup

It turns out that wiping the system disk is critical. I initially tried to just reinstall OS X. But for some reason the OS X installer would hang during startup — even if I booted directly from the installer DVD. I suspect that the installer attempts to read the user accounts on the system disk, and it can't cope with missing user accounts.

I initially tried wiping the disk using a GParted Live, but that just seemed to mangle the partition and failed to erase it. So then I put the Mac into Target Disk Mode and connected it to another Mac via Firewire; I then successfully used Disk Utility on the second Mac to wipe the disk. Thus in a scenario like this, I highly recommend using Target Disk Mode to wipe everything before reinstallation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.