add user script

mramola
New Contributor III

I am trying to add another user to our mac fleet using a script.  The script goes through without error and creates a user but no directory folder so when I attempt to log in as the "sub" it just spins and spins.  

Here is my script....what am I missing?

sudo dscl . -create /Users/sub
sudo dscl . -create /Users/sub UserShell /bin/bash
sudo dscl . -create /Users/sub RealName sub
sudo dscl . -create /Users/sub UniqueID 1000
sudo dscl . -create /Users/sub PrimaryGroupID 20
sudo dscl . -create /Users/sub NFSHomeDirectory /Users/sub 
sudo dscl . -passwd /Users/sub becker

7 REPLIES 7

mramola
New Contributor III

I got it figured out.  In case someone else needs this at some point here is my final script.  

 

sudo dscl . -create /Users/sub
sudo dscl . -create /Users/sub UserShell /bin/bash
sudo dscl . -create /Users/sub RealName sub
sudo dscl . -create /Users/sub UniqueID 1001
sudo dscl . -create /Users/sub PrimaryGroupID 20
sudo dscl . -create /Users/sub NFSHomeDirectory /Users/sub
sudo createhomedir -u sub -c
sudo dscl . -passwd /Users/sub becker

joshuasee
Contributor III

I would also note that dscl is nearing deprecation as a user creation technique. sysadminctl has an -addUser  switch that requires fewer steps and can avoid some of the pitfalls of dscl. You might also want to use sysadminctl to get a secure token for the account created. 

mramola
New Contributor III
Yes - I did read that dscl was heading out the door, I just needed to get
it to work at least once, and then I can make some changes. If you have a
full script using sysadminctl that you'd like to share that would be
great. I am very new to all of this.

Megan Ramola
Technology Assistant
Becker School District
763-261-4501 ext 3153

mickgrant
Contributor III

You can also just create a jamf policy with a custom trigger to create the user and then call it with a one-liner in your script with

this post was written in error, I have no knowledge of jamf schools... my mistake

 

 

mramola
New Contributor III
Hmmm....this is something I have never done before. Can you give some
better directions?

Megan Ramola
Technology Assistant
Becker School District
763-261-4501 ext 3153

When I wrote that, I thought you were using Jamf Pro,
I have not used Jamf school, so I do not know if that's an option for you.

Fluffy
Contributor III

On Github there is a script that utilizes sysadminctl called mkuser made by Pico. I haven't used it myself yet, but it's another option and is well documented.

https://github.com/freegeek-pdx/mkuser