Scripting OpenDirectory Users

So here’s the script I use to add users to OpenDirectory. The script requires the first and last names of the user and the user’s UID. We manually assign the UID and use it as the user’s initial password. Change [GID], [admin password], [group name], and /path/to/ to suit your needs.

#!/bin/bash # #This script adds a new user to OpenDirectory 081211 # #Usage: ./newuser.sh [firstname] [lastname] [uid] #Creating user account: dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 UserShell /bin/bash dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 RealName "$1 $2" dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 UniqueID $3 dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 PrimaryGroupID [GID] #Creating home directory: mkdir /path/to/home/$1$2 chown -R $1$2:[group name] /path/to/home/$1$2 chmod -R 700 /path/to/home/$1$2 dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -create /Users/$1$2 NFSHomeDirectory /path/to/nfs/folder/$1$2 #Set password: dscl -u diradmin -P [admin password] /LDAPv3/127.0.0.1 -passwd /Users/$1$2 $3