Managing User Accounts at the Command Line
OS X uses and open directory for storing information for user accounts. If you have ever installed OS X, or purchased a new computer, you will be asked to generate a new user account which will have administrative privileges. Perhaps you will add other accounts as well in the future and want to delete the first user account you originally created. Unfortunately, there is no way to do that from the Preference Pane. There are many options available at the command line that will allow you to manage user accounts within the Open Directory, using dscl, which is short for Directory Service Command Line Utility.
Delete a user account:
% sudo dscl /Local/Default -delete /Users/tom
Create a user account:
% sudo dscl /Local/Default -create /Users/tom
Set the user’s shell:
% sudo dscl /Local/Default -create /Users/tom UserShell /bin/ksh
Change the user’s password:
% sudo dscl /Local/Default -passwd /Users/tom PASSWD
Create and set the user’s home directory:
% sudo dscl /Local/Default -create /Users/tom NFSHomeDirectory /Local/Users/tom
Delete the user’s home directory:
% sudo dscl /Local/Default -delete /Users/tom NFSHomeDirectory /Local/Users/tom
Set the user’s group ID:
% sudo dscl /Local/Default -create /Users/tom PrimaryGroupID 350
Add the user to a group:
% sudo dscl /Local/Default -append /Groups/admin GroupMembership tom
Set the user’s GCOS or full name:
% sudo dscl /Local/Default -create /Users/tom RealName “Tom Smith”
If you had a configured Open Directory server, you can simply replace the text in the above examples from /Local/Default to /LDAPv3/{server-name}
If you want to simply browse the directory, just type dscl from the command line and browse around using standard UNIX commands such as cd, ls, etc.