Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What commands (or script) can create a fully functional user account on Mountain Lion, running only from the command line via terminal or ssh.

It looks like an existing pair of answers might work, but I wondered if there were a short script or tool for creating fully functional user accounts on Mountain Lion?

share|improve this question
up vote 21 down vote accepted

Here is a shell script I wrote at work to handle this as part of the NetInstall process (creating a local administrator account automatically during imaging process).

. /etc/rc.common
dscl . create /Users/administrator
dscl . create /Users/administrator RealName "Administrator Account"
dscl . create /Users/administrator hint "Password Hint"
dscl . create /Users/administrator picture "/Path/To/Picture.png"
dscl . passwd /Users/administrator thisistheaccountpassword
dscl . create /Users/administrator UniqueID 501
dscl . create /Users/administrator PrimaryGroupID 80
dscl . create /Users/administrator UserShell /bin/bash
dscl . create /Users/administrator NFSHomeDirectory /Users/administrator
cp -R /System/Library/User\ Template/English.lproj /Users/administrator
chown -R administrator:staff /Users/administrator

Some notes to mention:

  • I have this saved as an executable ".sh" file.
  • Since it executes during NetInstall it runs as root, and needs to run as root to work properly. You can also subtract the first two lines, add a "sudo" to the beginning of each subsequent line, and manually run these as individual commands in Terminal.
  • Modify UniqueID from 501 to a number that you will know is safe on all systems (501 is taken by the first account created on a Mac, generally something higher like 550 will probably be safe, depending on how many users you have on your system).
  • PrimaryGroupID of 80 creates an Admin user. Change to PrimaryGroupID of 20 to create a Standard user.
  • I've imaged well over 50 Macs this way with no issues. I use this account to run commands via SSH, to push out patches via ARD and to do local desk-side administration.
share|improve this answer
Looks promising - will test it out soon! – bmike Mar 4 '13 at 0:43
The problem I seem to have when I try and adapt this script to create regular users by passing variables to the script is that everything except for the last line works just fine. That is, dscl creates the user, and when I use dscl . list /users, the user shows up just fine, but chown does not recognize the user, and since I can't change the home directory permissions properly, it won't let that user log in. Any ideas? – user52842 Jul 8 '13 at 3:36
I wish I could. One of my weaknesses when it comes to shell scripting is that I never learned the usage of variables very well, mostly because I haven't actually needed to use them for anything at this point in my job. Maybe @bmike or someone else might be able to offer advice. – bispymusic Jul 10 '13 at 15:33
@HackintoshCoat can you post your script? In your command, you've typed lowercase "/users", when it is in fact "/Users". I doubt that's the issue with your script; but, fresh eyes checking it might be able to find the problem fairly quickly. I've got a similar script that actually sets up multiple users, so the usage of variables itself is not a problem. – Kent Jul 24 '13 at 8:16
Instead of the last two lines (cp -R ...; chown -R ...), you can use the command createhomedir -u administrator. createhomedir has a man page, too. – Alex Leach Feb 5 '14 at 12:13

To further automate this, the following line can be used to get the next "available" user id if you are running on a mac which already has users set up.

LastID=`dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1`

NextID=$((LastID + 1))

Then, the corresponding line in bispymusic's answer above could be changed:

 dscl . create /Users/administrator UniqueID $NextID
share|improve this answer

I have some updates on the above answer.

dscl / -append /Groups/admin GroupMembership newUserName

This command can used for making the user have Administrative access. If this command is not provided the user will automatically will be set as standard user.

dscl . create /Users/newUserName PrimaryGroupID 80

This sets user's primary group id. 80 means admin and 20 means staff. And setting to 20 will not make the user standard. Unless the first command is not mentioned.

share|improve this answer
To clarify, either of these commands will accomplish the same thing? – MaxGabriel Sep 6 '13 at 21:19
I prefer the first command, appending to /Groups/admin . – Vipin Johney Sep 27 '13 at 14:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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