How to change a local user account password on Mac OS X with a bash script

This little snippet of code shows you how to change the password of a local user account on Mac OS X.

# If the user account has a local home folder then change password. Else print account not found.
if [[ -e "/Path/To/Users/Home/Directory/" ]]
/usr/bin/dscl . passwd /Users/username newP@ssw0rd
# Delete the users login keychain
rm /Path/To/Users/Home/Directory/Library/Keychains/login.keychain
printf "Password successfully changed."
exit 0
printf "user account not found"
exit 1

Leave a Reply

Your email address will not be published. Required fields are marked *