MacOS: User Account Won’t Delete

Scenario

We were unable to delete an account using MacOS: System Preferences > Users & Groups.
After selecting the user to delete, and clicking the “-“, we were prompted for the password of the account we were attempting to delete, which failed. I don’t recall if the error was invalid password or user not found. We changed the password, to make sure we had the correct password, but the user delete still failed.

The account we were trying to delete used to be the original Administrator. A new Administrator was created, and the original Administrator was changed to a Standard user account.

As we couldn’t delete the account via the GUI, I spun up Terminal, and documented the commands I used to successfully delete the user account.

Remove a User Account Using Terminal

Enable root

  • This will ask for a user name and password of an admin user then ask to create a root password.
  • When done correctly you’ll see “dsenableroot:: ***Successfully enabled root user.”
dsenableroot

Display list of users, to make sure you use the correct user account, with the correct “case” of characters.

dscl . -list /users

Remove the user account

  • This will only remove the user access and not the files for that user.
sudo dscl . -delete /users/Guest

Move, not delete, all of the previous user files into a directory we can access should we need them later.

mkdir /users/administrator/Desktop/OldUserFiles/
sudo mv /users/Guest2 /users/administrator/Desktop/OldUserFiles/

Delete the user directory in /users/

rm -rf "/users/Guest2"

Disable root!!!! (Don’t forget to do disable root!!!)

  • This will ask for a user name and password of an admin user.
  • When done correctly you’ll see “dsenableroot:: ***Successfully disabled root user.”
dsenableroot -d

Reboot the system.

  • Until you reboot, the GUI may show the icon for the user, but the user name will be empty.

Environment

System: Apple MacBook Pro 13″
OS: MacOS Sierra v10.13.6
Date: 2021-12-31

Reference