Thursday, September 15, 2011

Delete Users and Groups from Terminal on Mac

This Process can be Useful in situations like the followings:
  • After the Installation of some Software like MySQL you can have some
    problem with the Automatically Created user.
  • If you try to add an User or Group from System>Preferences
    and you find it already exists but this doesn't permit you to Login on a
    Terminal Session.
So you need to open a Terminal Session ( /Applications/Utilities/Terminal.app)

a) To Delete a User
dscl . -delete /Users/yourUserName
b) To Delete a Group
dscl . -delete /Groups/yourGroupName


After you are Free to Re-Create User and Group from System Preferences.

If You Re-Create User and Group by System Preferences after you Should Repair Ownerships on Directories and Files Owned by the Deleted Users/Groups.
For example if you deleted and recreated "mysql" User and "mysql" Group after you will need to Recursively set ownership by:
sudo chown -R mysql:mysql /usr/local/mysql
Extra Indications:
Mac HOW-TO Make a Command Alias 4 Easy-Quick Execution