Creating an account via script

Bernard_Huang
Contributor III

Hi all

I want to create an account within the Macbook using JAMF policy > Script.

I've searched online some info, updated it with $4, $5, etc so that it fits JAMF Pro. But when I ran it, nothing happens.

Anyone got any suggestions?

#!/bin/bash username=$4 password=$5 adminRights=$6 dscl . -create /Users/$username dscl . -create /Users/$username UserShell /bin/bash dscl . -create /Users/$username RealName $username dscl . -create /Users/$username UniqueID "999" dscl . -create /Users/$username PrimaryGroupID 20 dscl . -create /Users/$username NFSHomeDirectory /Users/$username dscl . -passwd /Users/$username $password if [ "$adminRights" = "admin" ]; then dscl . -append /Groups/admin GroupMembership $username fi
6 REPLIES 6

Bernard_Huang
Contributor III

Belay that....
The account has been created :)
It's just that it didn't create a home directory. But I did find the account within System Preferences > Users.

I think I'm good now.

Lotusshaney
Contributor II

Just to let you know hat DSCL is restricted under 10.14 so you may have some problems using that script

sshort
Valued Contributor

I recommend using sysadminctl in High Sierra and Mojave, otherwise you'll run into issues with secureToken and enabling FileVault. dscl also seems to strip secureToken from users that already have it if using that command to reset the user's password in the future.

sudo sysadminctl -adminUser AdminUserHere -adminPassword AdminPasswordHere -addUser NewUserNameHere -fullName "Full Name Here" -password NewUserPasswordHere -admin

It auto sets the shell and UID, but you can specify those with additional flags. Check out sysadminctl --usage There's a password passthrough option - as well.

Aguiness
New Contributor III

why don't you use the function in the jamf binary it can create an account on the local machine

Lotusshaney
Contributor II

It not very flexible and sometimes fails on new OS versions until Jamf fix it.

Use Greg Negale’s python script if you want to make users. It does direct Directory Service calls

jhalvorson
Valued Contributor

Greg Negale's python script: https://github.com/gregneagle/pycreateuserpkg