Category filter
Script to remotely Create User Accounts on macOS devices
With the help of the scripts provided below, user management on macOS can be done with ease. Creating new user accounts, assigning appropriate roles, or even removing existing user accounts can be accomplished by the IT admin utilizing the “Execute Custom Script” feature provided by Hexnode UEM.
Scripting language – Bash
File extension – .sh
Create an Admin User account
1 2 3 4 5 6 7 |
#!/bin/sh export PATH=/usr/bin:/bin:/usr/sbin:/sbin USERNAME="Daniel" FULLNAME="Daniel.Hector" PASSWORD="One@Two#8" PASSWORDHINT="One to Eight" sysadminctl -addUser "$USERNAME" -fullName "$FULLNAME" -password "$PASSWORD" -hint "$PASSWORDHINT" -admin |
The “export” command is used to set the “PATH” variable as an environment variable. Environment variables are special variables that contain information about your login session. The directories “/usr/bin:/bin:/usr/sbin:/sbin” contain essential system binaries and commands used by the operating system. The “PATH” variable specifies the directories where the system looks for executable files when a command is entered. In this script, it ensures that the “sysadminctl” command can be found and executed since it is part of the system administration tools.
The “sysadminctl” command is used for managing user accounts from the command line. The “-addUser” option is used within “sysadminctl” to create a new user on macOS. “-admin” parameter grants administrative privileges to the user account.
Create a Standard User account
1 2 3 4 5 6 7 |
#!/bin/sh export PATH=/usr/bin:/bin:/usr/sbin:/sbin USERNAME="Daniel" FULLNAME="Daniel.Hector" PASSWORD="One@Two#8" PASSWORDHINT="One to Eight" sysadminctl -addUser "$USERNAME" -fullName "$FULLNAME" -password "$PASSWORD" -hint "$PASSWORDHINT" |
The administrator can provide the username and password of the new account against the USERNAME and PASSWORD fields respectively. The display name and password hint of the new account can be specified against the FULLNAME and PASSWORDHINT fields. The created user assumes the role of a standard user as the “-admin” parameter is not included in the “sysadminctl” command.
What happens at the device end?
A new user will be created, either as an admin or standard user, based on the configuration in the script. This user account will appear in System Settings/System Preferences > Users & Groups and will be able to log in using the password provided in the script.