# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/) action.

Scripting Language – Bash

File extension – .sh

 Disclaimer: 
The sample scripts provided below are adapted from third-party open-source sites.

 

Change user password
--------------------

Script to change user password on Mac

sudo dscl . -passwd /Users/username currentpassword newpassword 

   1

  sudo dscl . -passwd /Users/username currentpassword newpassword 

   

 

  

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 *username* from the *currentpassword* to a *newpassword*.

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

 Notes:- 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.