2007-07-10

[Mac OS X] Adding a User From the Command Line

Adding a User From the Command Line

This section shows a simple example of using the Directory Service command-line tool, dscl(1), to add a user to the system. The example specifies some of the properties that you would normally associate with any user.

Note: These commands must be run as the root user. If you are executing them from the command line manually, you should do this with sudo(8). If you are using them in a script, you should use sudo when running the script.

  1. Create a new entry in the local (/) domain under the category /users.

    dscl / -create /Users/portingunix

  2. Create and set the shell property to bash.

    dscl / -create /Users/portingunix UserShell /bin/bash

  3. Create and set the user’s full name.

    dscl / -create /Users/portingunix RealName "Porting Unix Applications To Mac OS X"

  4. Create and set the user’s ID.

    dscl / -create /Users/portingunix UniqueID 503

  5. Create and set the user’s group ID property.

    dscl / -create /Users/portingunix PrimaryGroupID 1000

  6. Create and set the user home directory. (Despite the name NFSHomeDirectory, this is the local path to the home directory.)

    dscl / -create /Users/portingunix NFSHomeDirectory /Local/Users/portingunix

  7. Set the password.

    dscl / -passwd /Users/portingunix PASSWORD

    or

    passwd portingunix

  8. To make that user useful, you might want to add them to the admin group.

    dscl / -append /Groups/admin GroupMembership portingunix

This is essentially what System Preferences does when it makes a new user, but the process is presented here so you can see more clearly what is going on behind the scenes with the NetInfo database. A look through the hierarchies in the NetInfo Manager application also helps you understand how the database is organized.

No comments: