Category filter

Script to Change User Password on Mac

IT administrators might desire to allocate a new password to the user for various reasons, such as improving security on the device. In such scenarios, you can run the below script to modify the login password for a user account from the Mac Terminal. With Hexnode UEM, admins can remotely run scripts using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Change user password

The above script utilizes the directory service command-line utility or dscl tool to modify the /User directory data (specifically the password). The passwd command is used to change the password for the user ‘New User’ from the oldpassword to a newpassword.

Note that the keychain password will also get updated to the new password following a device restart.


  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository