Managing users and groups in Mac OS X terminal
We can use dscl command to manage users in Mac OS X terminal.
Creating new user in Mac OS X
We can use “dscl” command to create new user in the system.
Below command will create an user with name “paul”
dscl . create /Users/paul
Below command will set the default shell for the user “paul” as “/bin/bash”
dscl . create /Users/paul UserShell /bin/bash
Below command will give user id – 999 to the user “paul”
dscl . create /Users/paul UniqueID 999
Below command will give group id – 111 to the user “paul”
dscl . create /Users/paul PrimaryGroupID 111
Below command will give set the home directory for user “paul” as “Local/Users/paul”
dscl . create /Users/paul NFSHomeDirectory /Local/Users/paul
Below command will set the password for the user “paul”
dscl . passwd /Users/paul <xxxxxx>
To give user the administrative privileges, you can use below command.
dscl . append /Groups/admin GroupMembership paul
Note that it is recommended to reboot the system, after creating an user with administrative privileges for changes to take effect.
Creating new group
You can use below commands to add new group in the Mac OS X system.
sudo dscl . -create /groups/dev
sudo dscl . -append /groups/dev gid 888
sudo dscl . -append /groups/dev passwd “**********”
Deleting a User and group
dscl . -delete /Users/paul
dscl . -delete /Groups/dev
Viewing all users in Mac OS X
$ dscl . -ls /Users
Viewing currently logged in users
Running command as different user
$ sudo -u <other-user> <command>