Is it possible to create a user without a home directory?

I want to create a user to run tomcat on my system and was wondering if it is possible to create a user without a home directory like it is possible in linux.


Solution 1:

Yes you can, using the following code. Note that the UniqueID, if less than 501, may not list the user in the Accounts pane of system preferences, depending upon the OS version. Be careful that it is not already assigned to another user account.

sudo dscl . -create /Users/ThisUserName
sudo dscl . -create /Users/ThisUserName UserShell /bin/bash
sudo dscl . -create /Users/ThisUserName UniqueID 505
sudo dscl . -create /Users/ThisUserName PrimaryGroupID 20
sudo dscl . -passwd /Users/ThisUserName Pa55w0rd

You can assign a home folder outside of the normal /Users/ hierarchy with:

sudo dscl . -create /Users/ThisUserName NFSHomeDirectory /path/to/your/home

If you want a clearer name to show up in the accounts preference:

sudo dscl . -create /Users/ThisUserName RealName "This User Name"

If you su to the new user without having set a NFSHomeDirectory, the $HOME defaults to /var/empty.