How to Create a new User from Terminal on Mac OSX

June 16th, 2011 by Regaz



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)
    usernewid=$((usermaxid+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!

(Visited 1 times, 1 visits today)
Share on Tumblr

Tags: , , , , ,


No Responses to “How to Create a new User from Terminal on Mac OSX”

  1. shalinil says:

    Good information. And i alway like to read the quality content. And i am really happy to found this information on your blog. Thanks for sharing this opportunity to leave a comment.