Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following command on OSX will change an Open Directory (Apple's LDAP) password. The $ is the prompt:

$ dscl -u diradmin -P 'password' /LDAPv3/ passwd /Users/username newpassword

I would love to turn this into an interactive shell script of some sort (let's call it 'odpasswd') that first prompts the admin for the username whose account they want to change passwords for, then for the password, along these lines:

$ odpasswd
$ Username you'd like to change passwords for?
$ New Password?
$ Done! Password changed successfully for username 'johnd' to 'secretpassword'

I'm not enough of a shell script expert to know how to turn this into something like this.

Your help is always much appreciated! Thanks!

share|improve this question
up vote 1 down vote accepted

You could define variables for the -P "$password". Also read about 'read' function in bash.

$ dscl -u diradmin -P 'password' /LDAPv3/ passwd /Users/username newpassword

This is an untested script, but you could figure it out.


read -p "For which user to change the password? " username
read -s "Enter the old password for $username " oldpassword
read -s "Enter the new password for $username " newpassword

dscl -u diradmin -P "$oldpassword" /LDAPv3/ passwd /Users/"$username" "$newpassword"
share|improve this answer
Thanks, that is just what I was looking for. Now it's working just great. Cheers! – Dan Oct 11 '12 at 21:36
read -s is a bash-only convention. For a sh-compatible script, turn off echo with stty -echo right before the read command, then turn it back on with stty echo afterwards. – bonsaiviking Oct 17 '12 at 14:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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