In general, you can create a user via Terminal in macOS using Apple's documented method. However, macOS Mojave introduced various security mechanisms that cause scripts to fail when changing user account settings like UID and NFSHomeDirectory, both of which I need to change for how I use these accounts. So, the script to create a new home folder now fails, unless I have a GUI to approve the change being made. Is there any way to create a user and modify the settings without disabling any security settings? There's nothing in the TCC database I can find to allow this script to run, and it's not feasible to run this on every machine I need it deployed to.
#!/bin/bash new_uid=401 username=xmpleuser homefolder=/var/xmplfolder sudo dscl . -delete Users/$username sudo rm -r $homefolder echo "Creating $username ( $new_uid ) user..." sudo dscl . -create /Users/$username UniqueID $new_uid sudo dscl . -append /Users/$username NFSHomeDirectory $homefolder sudo dscl . -append /Users/$username home $homefolder sudo dscl . -append /Users/$username UserShell /sbin/nologin
And I've tried:
#!/bin/bash new_uid=401 username=xmpleuser homefolder=/var/xmplfolder sudo dscl . -delete Users/$username sudo rm -r $homefolder sudo sysadminctl -addUser $username -UID $new_uid -shell /sbin/nologin -home $homefolder
I also tried the script linked on this question, and the exact Terminal commands in the Apple article mentioned earlier.