Category Filter

Script to Change User Password on Mac

Sometimes, users might forget their password or administrators might desire to allocate a new password to the user. In such scenarios, you can use the below script to modify the login password for a user with a single line command from the Mac Terminal.

Device admins can remotely run scripts on Macs managed with Hexnode using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh

Disclaimer:


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.

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.