Mac OS X – Remove Users In Terminal/SSH

Recently I had to remove users from a Mac that was on a network only with SSH available.

In this document I use the user name “administrator” as the account that I do the work in and would like to keep, your user name may be different.

First we need to enable root

dsenableroot

This will ask for a user name and password of an admin user then ask to create a root password and have you confirm it.

When done correctly you will see “dsenableroot:: ***Successfully enabled root user.”

Next we want to remove the users, note this will only remove the user access and not the files for that user.

sudo dscl . delete /users/Guest
sudo dscl . delete /users/jdoe1
sudo dscl . delete /users/jdoe2
sudo dscl . delete /users/marketing

OPTIONAL: Force the startup video to play again for the first login

sudo rm -r /var/db/.AppleSetupDone

Now we will move, not delete, all of the previous user files into a directory we can easily access should we need them later. This is important if you don’t really know what people were storing.

mkdir /users/administrator/Desktop/OldUserFiles/
sudo mv /users/Guest /users/administrator/Desktop/OldUserFiles/
sudo mv /users/jdoe1 /users/administrator/Desktop/OldUserFiles/
sudo mv /users/jdoe2 /users/administrator/Desktop/OldUserFiles/
sudo mv /users/marketing /users/administrator/Desktop/OldUserFiles/

When done disable root

dsenableroot -d

This will ask for a user name and password of an admin user.

When done correctly you will see “dsenableroot:: ***Successfully disabled root user.”

References:
Enable Root: OSXDaily.com

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.