Delete own user from Mac OS 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?
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.


Create a new admin with a different name than ali (e.g. ali2)
After the configuration is done create a new admin with a different name than ali (e.g. ali3)
Logout as ali2 and login as ali3
Modify ali2 (e.g. name/user directory/user id etc.) with Users &amp; 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.