I want to be able to create new users from the command line when I am logged in as an administrator. Specifically, I am looking for an equivalent of the adduser command on Linux.

2 Answers 2


There is a good script available at http://wiki.freegeek.org/index.php/Mac_OSX_adduser_script However it has several typos and sometimes is not flexible enough, so here is my modified version of it with some improvements:

# =========================
# Add User OS X Interactive Command Line
# =========================

    local __UIDS=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ugr)

    #echo $__UIDS
    local __NewUID
    for __NewUID in $__UIDS
        if [[ $__NewUID -lt 499 ]] ; then

    echo $((__NewUID+1))

    # Find out the next available user ID
    local __MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
    echo $((__MAXID+1))

if  [ $UID -ne 0 ] ; then echo "Please run $0 as root." && exit 1; fi

read -p "Enter your desired user name: " USERNAME

read -p "Enter a full name for this user: " FULLNAME

read -s -p "Enter a password for this user: " PASSWORD
read -s -p "Validate a password: " PASSWORD_VALIDATE

    echo "Passwords do not match!"
    exit 1;

# ====

# A list of (secondary) groups the user should belong to
# This makes the difference between admin and non-admin users.

read -p "Is this an administrative user? [y/n] (n): " GROUP_ADD

if [ "$GROUP_ADD" = n ] ; then
    SECONDARY_GROUPS="staff"  # for a non-admin user
elif [ "$GROUP_ADD" = y ] ; then
    SECONDARY_GROUPS="admin _lpadmin _appserveradm _appserverusr" # for an admin user
    echo "You did not make a valid selection!"
    exit 1;

# ====

# Create a UID that is not currently in use

read -p "Should this user have interactive access?  [y/n] (y): " IS_INTERACTIVE

if [ "$IS_INTERACTIVE" = y ] ; then
elif [ "$IS_INTERACTIVE" = n ] ; then
    echo "You did not make a valid selection!"
    exit 1;

echo "Going to create user as:"
echo "User name: " $USERNAME
echo "Full name: " $FULLNAME
echo "Secondary groups: " $SECONDARY_GROUPS
echo "UniqueID: " $USERID

read -p "Is this information correct?  [y/n] (y): " IS_INFO_CORRECT

if [ "$IS_INFO_CORRECT" = y ] ; then
    echo "Configuring Open Directory..."
elif [ "$IS_INFO_CORRECT" = n ] ; then
    echo "User creation cancelled!"
    exit 1;
    echo "You did not make a valid selection!"
    exit 1;

# Create the user account by running dscl (normally you would have to do each of these commands one
# by one in an obnoxious and time consuming way.

dscl . -create /Users/$USERNAME
dscl . -create /Users/$USERNAME UserShell /bin/bash
dscl . -create /Users/$USERNAME RealName "$FULLNAME"
dscl . -create /Users/$USERNAME UniqueID "$USERID"
dscl . -create /Users/$USERNAME PrimaryGroupID 20
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
dscl . -passwd /Users/$USERNAME $PASSWORD

# Add user to any specified groups
echo "Adding user to specified groups..."

    dseditgroup -o edit -t user -a $USERNAME $GROUP

# Create the home directory
echo "Creating home directory..."
createhomedir -c 2>&1 | grep -v "shell-init"

echo "Created user #$USERID: $USERNAME ($FULLNAME)"
  • At least on 10.12/Sierra this could be problematic. When I tried it, it was creating directories for every single user on the network. Specifically, using 'createhomedir' without specifying '-u username' is probably ill-advised. Feb 4, 2017 at 10:49

I think you're looking for the dscl command. Niutil sounds like NetInfo which is deprecated in OS X in favor of Open Directory aka LDAP.

Dscl, or Directory Services Command Line, can be used to edit Open Directory for both a local or remote user data store. It can be done with sudo commands but it's easier to use as root.

Here's a short and highly inadequate tutorial: In the terminal, sudo -s to switch your user to root. To create a functional user account named dscl2, you need to do the following:

dscl . -create /Users/dscl2

dscl . -create /Users/dscl2 UserShell /bin/bash

dscl . -create /Users/dscl2 RealName "DSCL 2"

dscl . -create /Users/dscl2 UniqueID 8005

dscl . -create /Users/dscl2 PrimaryGroupID 20

dscl . -create /Users/dscl2 NFSHomeDirectory /Users/dscl2

dscl . -passwd /Users/dscl2 password

The UUID is typically around 501 or larger. 501 is the default UID for the first account created. UIDs less than 500 don't show up in the Accounts pane by default. Choose whatever number you want, but make sure it is unique on the local system. Don't overwrite an existing UID or you will have big problems.

Dscl has an interactive mode as well that works a little differently. Enter just "dscl" at the prompt to enter interactive mode.

If you're in Interactive mode, type ls to list which directories are available. You should see BSD, LDAP and Local. You navigate through the directories with cd. See your friend the man page for more info.

  • 2
    I know you warned us that this was inadequate, but it would be great to see the full set of steps required to create an account, even after dscl is done. For example, does a /Users/dscl2 folder need to be created? how to apply the ACLs? Feb 22, 2012 at 6:18
  • 1
    This answer is correct, but the script in @anton-matosov answer is great. Runs the same commands.
    – bmucklow
    Apr 30, 2013 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .