1

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.

1
  • 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. – Spiff Dec 9 '16 at 0:49
7

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
6
  • I understand and have tried using this before but it says something like '-crwate bad key path or something – DuckyQuack Dec 16 '16 at 1:07
  • If you can give a more precise error description, we may be able to figure this out – SaxDaddy Dec 16 '16 at 4:13
  • 1
    the output is create: Invalid Path – DuckyQuack Dec 21 '16 at 21:44
  • Which command of the ones above threw the error? And what version of OSX and dscl are you running? – SaxDaddy Dec 22 '16 at 1:51
  • 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 – SaxDaddy Dec 22 '16 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.