2

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.

I've tried:

#!/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

They both give a warning box: "App" would like to administer your computer

I also tried the script linked on this question, and the exact Terminal commands in the Apple article mentioned earlier.

  • It works if you use ssh to login into an admin account, either locally or remote. – nohillside May 7 at 18:33
  • Could you verify the version of macOS you are running on the machine you're remotely connected to? sw_vers in Terminal should give it to you. – splemp May 15 at 16:29
  • 10.14.5 (and 10.14.4 before). But I just tried again, the results are, hmm, strange. Using just dscl sometimes works and sometimes fails (haven't found a pattern yet), using sysadminctl always fails. Going to delete my answer in a day, isn't really helpful if it doesn't work reliably. – nohillside May 15 at 18:48

You must log in to answer this question.

Browse other questions tagged .