Creating a user from the commandline on OS X
The following will create a user USER_NAME in the group USER_NAME
with a home directory /Users/USER_NAME, it assumes you have sudo
access and are currently in /Users
-
Find the next free uid by running the following
nireport . /users name uid
create user, assuming a free uid of 505 from the previous step.
This should be a single line.
echo USER_NAME::505:505:USER_NAME build user:0:0:USER_NAME
User:/Users/USER_NAME:/bin/bash | sudo niload -v passwd /
Set password
sudo passwd USER_NAME
create group
echo 'USER_NAME:*:505: USER_NAME' | sudo niload -v group /
create user directory
mkdir USER_NAME
change ownership
sudo chown USER_NAME:USER_NAME USER_NAME
make sure you can login
ssh USER_NAME@localhost
As an aside here is how to delete a user via the command line.
-
check the user exists
dscl . read /users/USER_NAME
delete the users group
sudo dscl . delete /groups/USER_NAME
delete the user
sudo dscl . delete /users/USER_NAME
delete user home directory
sudo rm -rf USER_NAME
Taken from