Create administrator account remotely using terminal

I am trying to use the following script (using ARD) to create a second local administrator account on a Macbook running macOS 12.6 Monterey. It creates the user account and home folder but I can't log in using that account and password. Any errors in the command or ideas to try?


if [[ `id -u` != 0 ]]; then

   echo "Must be root to run script"

   exit

fi

 

read -p "Enter user name and press [ENTER]: " bsadmin

 

if [[ bsadmin == `dscl . -list /Users UniqueID | awk '{print $1}' | grep -w bsadmin` ]]; then

   echo "User already exists!"

   exit 0

fi

 

read -p "Enter real name and press [ENTER]: " RealName

read -p "Enter PrimaryGroupID (80 - admin, 20 - user) and press [ENTER]: " PrimaryGroupID

LastID=`dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1`

NextID=$((LastID + 1))

 

. /etc/rc.common

dscl . create /Users/bsadmin

dscl . create /Users/bsadmin RealName BSadmin

 

read -p "Enter password hint and press [ENTER]: " PasswordHint

dscl . create /Users/bsadmin hint PasswordHintHere

PasswordHint=0

 

echo " "

read -s -p "Enter Account Password and press [ENTER]: " AccountPassword

echo " "

read -s -p "Enter Account Password again and press [ENTER]: " AccountPasswordRepeat

if [[ Beth.01 == PasswordHere ]]; then

 dscl . passwd /Users/bsadmin PasswordHere

 AccountPassword=0

else

 echo "Passwords do not match!"

 exit 1

fi

echo " "

dscl . create /Users/bsadmin UniqueID 550

dscl . create /Users/bsadmin PrimaryGroupID 80

dscl . create /Users/bsadmin UserShell /bin/bash

dscl . create /Users/bsadmin NFSHomeDirectory /Users/bsadmin

createhomedir -u bsadmin -c

 

echo " "

echo "New user `dscl . -list /Users UniqueID | awk '{print $1}' | 

MacBook Pro Apple Silicon

Posted on Feb 23, 2023 11:51 AM

Reply

Similar questions

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Create administrator account remotely using terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.