Posted on 05-21-2020 07:17 PM
I'm looking to see if there is a way to mass create macOS user accounts. I need to create over 100 accounts. I think it can just count up with an example like:
user01, user02, user03, and etc.
Also the same for the password example:
Password01, Password02, Password03, and etc.
I think a script would work best just not sure how to do this.
Posted on 05-22-2020 04:07 AM
A directory service is really the only solution that should be considered for something like this, but if going local is the only option you would really just need a csv with the pertinent information and then you could just feed that into a loop that calls sysadminctl with the pertinent fields, referencing the appropriate admin account and that should do it.
Posted on 05-22-2020 08:17 AM
If you're just looking to create a list of local accounts that all follow the format you mention above, it can be done in a script. Something like this may work, but I have never done this myself, so please be sure to look it over carefully and run a lot of tests.
#!/bin/bash
function createAccount ()
{
/usr/local/bin/jamf createAccount
-username "$USERNAME"
-realname "$FULLNAME"
-password "$PASSWORD"
-home "/Users/$USERNAME"
-shell /bin/zsh
}
for i in $(seq -f "%03g" 1 105); do
if [[ ! -d "/Users/user$i" ]]; then
USERNAME="user$i"
FULLNAME="User$i"
PASSWORD="password$i"
createAccount
fi
done
Basically, using the seq
command to generate a list of account names and password as it iterates through the list until it reaches the number you specify (105 in my script above, edit that as needed). It pads each number so there are at last 3 digits. i.e. 1 becomes 001, 99 becomes 099 and anything over 100 stays as is. Once it determines the variables it runs a function for each one that uses the jamf binary to create the account using those variables.
If you think this might work for you, I'd suggest testing it out on a machine that you don't mind wiping if needed, just in case something goes wrong.
Posted on 05-22-2020 07:25 PM
@mm2270 Thanks is there a way to do this without using Jamf? The Mac I'm using will not be enrolled in Jamf.
Posted on 05-25-2020 01:03 AM
Hi @kericson (jeez how many of the kericson are you)
Good questions but probably not the place for the answer. I did see this: https://apple.stackexchange.com/questions/226073/how-do-i-create-user-accounts-from-the-terminal-in-mac-os-x-10-11
dscl was the first thing I thought of too - not sure if there is a more elegant (simpler way). You could combine it with @mm2270 routine instead of the jamf binary.
Is it for exams? If so and if you have Jamf you could do it a lot better especially locking stuff down
Regards,
David
Posted on 05-25-2020 11:32 AM
I wouldn’t use dscl to create new accounts. The more approved binary to use is sysadminctl
@kericson If you just swap out the jamf binary calls in my script with sysadminctl ones then it should work with any Mac running an OS from the last 6 or so years.
To get the proper syntax to use run sysadminctl -help
in Terminal. Post back if you need any more help.