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.

#!/bin/bash
 
# If the user account has a local home folder then change password. Else print account not found.
if [[ -e "/Path/To/Users/Home/Directory/" ]]
then
/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
else
printf "user account not found"
exit 1
fi

Leave a Reply

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

*