I’ve seen several environments, especially in educational institutions, in which system administrators maintain lists with user names and passwords.
When you upgrade from Tiger to Leopard server or when you want to clean install a server system, it can sometimes be useful to import users into Workgroup Manager and then import user passwords (which can not be exported using WGM) from an additional list.

This script can do the job for you:

#!/bin/bash
#
##############################
#
# changeodpasswd 1.0, 05/2008 by Andre Aulich
# www.andre-aulich.de
#
# This script is supposed to be invoked on an
# Open Directory Master. It reads your users'
# names and passwords from a text file in the
# form of
# shortname1 password1
# shortname2 password2
#
# Usage: changeodpasswd InputTextFile
#
##############################

# First, extract a list of users out of our list:

USERS=$(cat "$1" | awk -F" " '{print $1}')

# Now find the password for each user:

for USERNAME in $USERS
do

# The following line searches the input file for
# the given user name (The -w flag in grep makes sure,
# that e.g. user1 and user12 are treated as separate
# users). Then it writes the related password into the
# variable USERPASS.

USERPASS=$(cat "$1" | grep -w $USERNAME | awk -F" " '{print $2}')

# The following line actually enters the user's password into Open Directory:

dscl -u diradmin -P DirPass /LDAPv3/127.0.0.1/ -passwd /Users/$USERNAME $USERPASS || echo "User $USERNAME doesn't exist."

# Please replace 'diradmin' with your directory master's shortname.
# Replace 'DirPass' with your directory master's password.
# If you run this command on an Open Directory master, the part
# '/LDAPv3/127.0.0.1/' can be left alone.
# If you are running a standalone server, use '.' instead.

done

Please use at your own risk and do some testing before you apply this to your production system.

Posted on by André Aulich. This entry was posted in Mac OS X Server.

Comments are closed.