How to create a user from the macOS command line

14,495

There are a few steps to create a user account from the command line. The good news is that you're using the right tool, dscl. What you're missing are the separate components that comprise a user account. You have to create these manually.

sudo dscl . -create /Users/someuser
sudo dscl . -create /Users/someuser UserShell /bin/bash
sudo dscl . -create /Users/someuser RealName "Lucius Q. User"
sudo dscl . -create /Users/someuser UniqueID "1010"  #use something not already in use
sudo dscl . -create /Users/someuser PrimaryGroupID 80
sudo dscl . -create /Users/someuser NFSHomeDirectory /Users/soemuser

You can then use passwd to change the user's password, or use:

sudo dscl . -passwd /Users/someuser password

You'll also have to create the user's home directory and change ownership so the user can access it. And be sure that the UniqueID is, in fact, unique.

This line will add the user to the administrator's group:

sudo dscl . -append /Groups/admin GroupMembership someuser
Share:
14,495

Related videos on Youtube

DuckyQuack
Author by

DuckyQuack

My dad is using my profile to find a job... I only use python and is looking towards java.. But that's it.

Updated on September 18, 2022

Comments

  • DuckyQuack
    DuckyQuack over 1 year

    I want to know how to create a user account from the macOS command line.

    If I try to use the well known dscl . -create /Users/blah... it doesn't work.

    Also if you type dscl the output is like

    Entering interactive mode...
     >
    

    I am also still trying to figure out the -auth and -authonly part too.

    • Spiff
      Spiff over 7 years
      I edited your question to remove your references to bash. You're struggling with the dscl tool, not bash. It would help if you'd show exactly what you entered and what result you got. Also, you might be able to skip the -auth stuff if you use sudo to run dscl as the superuser.
  • DuckyQuack
    DuckyQuack over 7 years
    I understand and have tried using this before but it says something like '-crwate bad key path or something
  • SaxDaddy
    SaxDaddy over 7 years
    If you can give a more precise error description, we may be able to figure this out
  • DuckyQuack
    DuckyQuack over 7 years
    the output is create: Invalid Path
  • SaxDaddy
    SaxDaddy over 7 years
    Which command of the ones above threw the error? And what version of OSX and dscl are you running?
  • SaxDaddy
    SaxDaddy over 7 years
    Also, did you run the commands as root or as a regular user? Try using sudo before the commands. I changed the answer above to show sudo usage
  • DuckyQuack
    DuckyQuack over 7 years
    SaxDaddy, all of the -create commands