I want to be able to create new users from the command line when I am logged in as an administrator. Specifically, I am looking for an equivalent of the adduser command on Linux.

link|improve this question
feedback

2 Answers

up vote 4 down vote accepted

I think you're looking for the dscl command. Niutil sounds like NetInfo which is deprecated in OS X in favor of Open Directory aka LDAP.

Dscl, or Directory Services Command Line, can be used to edit Open Directory for both a local or remote user data store. It can be done with sudo commands but it's easier to use as root.

Here's a short and highly inadequate tutorial: In the terminal, sudo -s to switch your user to root. To create a functional user account named dscl2, you need to do the following:

dscl . -create /Users/dscl2

dscl . -create /Users/dscl2 UserShell /bin/bash

dscl . -create /Users/dscl2 RealName "DSCL 2"

dscl . -create /Users/dscl2 UniqueID 8005

dscl . -create /Users/dscl2 PrimaryGroupID 20

dscl . -create /Users/dscl2 NFSHomeDirectory /Users/dscl2

dscl . -passwd /Users/dscl2 password

The UUID is typically around 501 or larger. 501 is the default UID for the first account created. UIDs less than 500 don't show up in the Accounts pane by default. Choose whatever number you want, but make sure it is unique on the local system. Don't overwrite an existing UID or you will have big problems.

Dscl has an interactive mode as well that works a little differently. Enter just "dscl" at the prompt to enter interactive mode.

If you're in Interactive mode, type ls to list which directories are available. You should see BSD, LDAP and Local. You navigate through the directories with cd. See your friend the man page for more info.

link|improve this answer
I know you warned us that this was inadequate, but it would be great to see the full set of steps required to create an account, even after dscl is done. For example, does a /Users/dscl2 folder need to be created? how to apply the ACLs? – Nathan Garabedian Feb 22 at 6:18
feedback

maybe this helps: http://stackoverflow.com/questions/855786/mac-os-x-new-users-from-command-line

link|improve this answer
I tried that. Except niutil does not exist on my system. – Buzzy Oct 24 '10 at 12:16
feedback

Your Answer

 
or
required, but never shown

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