Category filter

Script to delete user account on Mac

When employees leave an organization, the corporate devices assigned to them are re-distributed to other workers in the firm. Hence, organizations may require to delete the data and user account from the devices. However, manually doing this task is a time-consuming process. Hexnode lets you deploy scripts to delete the user account from Mac devices.

Scripting language – Bash

File extension – .sh


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

Delete the user account

The ‘sysadminctl’ has been introduced on macOS 10.13. It enables you to manage user accounts much more easily compared to the ‘dscl’ command.


  • The user account should be granted the Secure Token before attempting to delete it using this script.
  • The Hexnode Service app needs to be given full disk access for these scripts to work.
  • The user who has the only Secure Token on the device cannot be deleted. To delete this user, you need to add a new user, grant a Secure Token to it, and then try deleting the former user.

Even after the execution of the script, the user’s home folder will not be deleted. The user data will remain on the device and can be retrieved later if needed by an admin.

Delete directories and files of the user

The user account and all associated data will be erased from the device if both commands are executed successively.


  • Replace <username> with the username of the account to be deleted.
  • You can eliminate spaces in the username when substituting it in the script.
  • 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