Error while trying to create an account in single user mode on OS X Mavericks
On OS X Mavericks, I am trying to create an account using single user mode, using the following script.
#! /bin/bash
# create user
dscl . -create /Users/hiddenuser
dscl . -create /Users/hiddenuser UserShell /bin/bash
dscl . -create /Users/hiddenuser RealName "Hidden User"
dscl . -create /Users/hiddenuser UniqueID "401"
dscl . -create /Users/hiddenuser PrimaryGroupID 20
dscl . -create /Users/hiddenuser NFSHomeDirectory /var/hiddenuser
dscl . -passwd /Users/hiddenuser password
However, when I run this script, I get 6 copies of the same error:
/System/Library/LaunchDaemons/com.apple.DirectoryServicesLocal.plist: No such file or directory
How do I fix this? Do I need to download a new /System/Library/LaunchDaemons/com.apple.DirectoryServicesLocal.plist ?
Thanks
Note: I have tried changed 401 to other values below 501, and I am getting the same result.
Solution 1:
After starting in Single User Mode enter:
/sbin/fsck -fy
/sbin/mount -uw /
Launch opendirectoryd:
launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist
/System/Library/LaunchDaemons/com.apple.DirectoryServicesLocal.plist doesn't exist anymore!
Then execute:
dscl . -create /Users/hiddenuser
dscl . -create /Users/hiddenuser UserShell /bin/bash
dscl . -create /Users/hiddenuser RealName "Hidden User"
dscl . -create /Users/hiddenuser UniqueID "401"
dscl . -create /Users/hiddenuser PrimaryGroupID 20
dscl . -create /Users/hiddenuser NFSHomeDirectory /var/hiddenuser
dscl . -passwd /Users/hiddenuser password
The commands yield errors but the user is properly created. Executing /bin/bash /path/to/script.sh
directly after loading opendirectoryd didn't work for me for no apparent reason. On a second attempt using a UID >500 it worked though!
In Yosemite and more recent OS X versions creating a hidden user like this is not recommend. Instead use a free UniqueID >500 and use an additional command:
dscl . -create /Users/hiddenuser IsHidden 1