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.
Create a new entry in the local (
/) domain under the category/users.dscl / -create /Users/portingunixCreate and set the shell property to
bash.dscl / -create /Users/portingunix UserShell /bin/bashCreate and set the user’s full name.
dscl / -create /Users/portingunix RealName "Porting Unix Applications To Mac OS X"Create and set the user’s ID.
dscl / -create /Users/portingunix UniqueID 503Create and set the user’s group ID property.
dscl / -create /Users/portingunix PrimaryGroupID 1000Create 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/portingunixSet the password.
dscl / -passwd /Users/portingunix PASSWORDor
passwd portingunixTo 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:
Post a Comment