How to create a user from the macOS command line
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
Related videos on Youtube
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, 2022Comments
-
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 likeEntering interactive mode... >
I am also still trying to figure out the
-auth
and-authonly
part too.-
Spiff over 7 yearsI edited your question to remove your references to bash. You're struggling with the
dscl
tool, notbash
. 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 usesudo
to rundscl
as the superuser.
-
-
DuckyQuack over 7 yearsI understand and have tried using this before but it says something like '-crwate bad key path or something
-
SaxDaddy over 7 yearsIf you can give a more precise error description, we may be able to figure this out
-
DuckyQuack over 7 yearsthe output is
create: Invalid Path
-
SaxDaddy over 7 yearsWhich command of the ones above threw the error? And what version of OSX and
dscl
are you running? -
SaxDaddy over 7 yearsAlso, did you run the commands as root or as a regular user? Try using
sudo
before the commands. I changed the answer above to showsudo
usage -
DuckyQuack over 7 yearsSaxDaddy, all of the -create commands