How to Create A New User From Terminal on Mac OSX

June 16, 2011 | By Duchateaux.

This Article shows you How to Create a New User from Command Line on Mac OSX.

  1. Open a Terminal Session

  2. Find an Unset Users ID:
    usermaxid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
  3. Next Find the ID of the Group for the User:
    groupid=$(dscl . -read /Groups/ PrimaryGroupID | perl -wlne 'print $1 if/(d+)/')
  4. Proceed to Create User and Set the Password:

    dscl . -create /Users/newuser
    dscl . -create /Users/newuser UserShell /bin/bash
    dscl . -create /Users/newuser RealName "Lucius Q. User"
    dscl . -create /Users/newuser UniqueID $usernewid
    dscl . -create /Users/newuser PrimaryGroupID $groupid
    dscl . -create /Users/newuser NFSHomeDirectory /Users/luser
    dscl . -passwd /Users/newuser password

  5. Create the User’s Directories Tree:
    cp -R /System/Library/User Template/English.lproj /Users/newuser
    chown -R newuser:staff /Users/newuser
  6. To Add the New User to Admin Group:

    dscl . -append /Groups/admin GroupMembership luser

Bless The Lord!

QuickChic Theme • Powered by WordPress