When you set up OS X for the first time, your initial account will be an administrative one, allowing you to configure the system and install applications. Albeit rare, errors that occur when upgrading or restoring from backup, or otherwise when making heavy modifications to the system, could result in your admin account being destroyed so you cannot log in to it or use it for changing system settings.
If it happens then one quick but well-known and convenient trick for recovering administrative status on a system trigger Apple’s Setup Assistant tool. This will run before any accounts have been loaded, and will run in “root” mode, allowing you to create accounts on your Mac.
Even though the Setup Assistant only runs once when you first install OS X, it remains on your computer and is prevented from running by the presences of a hidden file called “.AppleSetupDone” in a system folder on your Mac. Therefore, to have the Setup Assistant run again so you can create a fresh admin account, you simply need to remove this file:
- Reboot your Mac and hold Command-S at the boot chimes to load into Single User mode.
- At the command prompt, run the following command to make the filesystem writable:
mount -uw /
- Run the following command to remove the hidden file:
rm /var/db/.AppleSetupDone

With the .AppleSetupDone file removed, rebooting will allow you to use this screen to create a new administrative account (click image for larger view).
When complete, enter “reboot” and the prompt to restart the system, and you will now see the Setup Assistant load when OS X starts up. Proceed through its various screens, and create your new account. You might consider using a different username than any previous accounts on the system, to ensure there are no conflicts with the present and faulty accounts.
Now you can log into the new admin account, and better manage the prior ones on your system, including deleting and recreating them accordingly.
Given that this method can be used to gain administrative access to OS X systems, you might be concerned about security risks it poses. Granted, if you have sensitive documents on your system, then anyone can reset account passwords or get admin access in this way, and be able to access the documents; however, there are a few steps you can take to ensure your system is safe.
The next option is to set a firmware password for your Mac, which will prevent booting to alternative boot modes and external disks. To do this, reboot to the OS X installation drive (be it a DVD or the Recovery HD partition in OS X Lion or later), choose your language when prompted, and then choose the “Firmware Password” option in the Utilities menu. Enter your password in the appropriate fields, and then nobody will be able to reset PRAM, boot to Safe Mode, Single User mode, or to alternative boot drives unless they either disable the password or supply it when prompted.
THANK YOU
also when you create your new account, make your home directory the same as the admin account you lost so you will log on into the right folder. Plus, TICK THAT YOU WANT TO START UP WITH NOTHING.
The problem explained is absolutely correct. I’m unfortunately not coming in root mode as Command S doesn’t function.
sorry i have os x 10.11 so i believe it doesn’t work
i need help with that
Now my system will not boot
Just wonder if you destroyed the boot partition. I did on a new iMac that I bought and there is a way of restoring it through Terminal, but very few know about it and it has to be done right.
What an enormous security risk.
I’ve just stumbled across this page as I ran into this issue restoring a friend’s MBP after a HD failure. When I ran Migration Assistant it crashed and left the Mac with only a Standard account. This process fixed it within 5 minutes.
However, think about what is happening here. All you need is physical access to a Mac running OS X, 5 minutes alone with it, 2 CLI commands and a reboot and you can basically pwn the machine by creating a new admin account and then you can do whatever you want.
I’m reporting this to Apple, I think it’s absolutely staggering that this is even an option.