I was wondering if it is possible to delete my one and only user account because I am creating a script to add and remove users on my Mac.

I have this command here:

sudo /usr/bin/dscl . -delete "/Users/ali"

I'm a little bit worried to test that because I don't want to delete my only user with all my files so is it possible?

  • 1
    You can try to add a new user and test with it, like that if your script works like it should, you'll keep all your data
    – Abel
    Dec 11, 2017 at 13:41
  • 2
    For what it's worth, if you run the script with sudo, you are effectively running it as root, so whatever safeguards might be present for the current user, these won't work in this case, because the current user is actually a different one.
    – Sven
    Dec 11, 2017 at 13:45
  • Adding and removing users on the mac via command-line interface is not a great idea and I don't advise trying to do so. Please see my answered question here for a bit more info. apple.stackexchange.com/questions/286749/…
    – Jahhein
    Dec 11, 2017 at 15:45
  • @klanomath thank you for fixing my link. I commented it because it doesn't answer the question.
    – Jahhein
    Dec 11, 2017 at 19:38
  • As long as you have a backup and/or don’t delete the user files, you can always boot to single user mode, remove the /var/db/.AppleSetupDone file and then restart. The setup assistant will let you set up a new admin account and then you can re-create the missing accounts, reusing the old home folders.
    – bmike
    Dec 11, 2017 at 20:45

1 Answer 1


The command sudo /usr/bin/dscl . -delete "/Users/ali" will remove the user ali from the local Directory Services database.

After login out you won't be able to login with user ali again. The user folder of ali won't be deleted.

To delete the folder /Users/ali and its content an additional command is necessary.

The user ali can be recreated though by booting to single user mode and using the remove .AppleSetupDone file trick in a two-stage process.

  1. Create a new admin with a different name than ali (e.g. ali2)
  2. After the configuration is done create a new admin with a different name than ali (e.g. ali3)
  3. Logout as ali2 and login as ali3
  4. Modify ali2 (e.g. name/user directory/user id etc.) with Users & Groups PrefPane/Directory Utility.app/command line to restore the previous entries of ali.

This won't work if your main volume is encrypted with FileVault2!

It's absolutely not recommended to test user creation/deletion scripts like this on your production Mac. Download VirtualBox, create a virtual machine running macOS and test your scripts inside there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .