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.
1 Answer
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
.
-
2If you want to create an account to run
tomcat
, I'd suggest not to give it a password, a shell of/usr/bin/false
, to give it an ID = 80 (below 500), and a name of_tomcat
(to follow the rules on MacOS X).– danJul 18, 2013 at 16:34 -
@danielAzuelos using /bin/false as the home directory prevents me from su-ing to the user. Jul 22, 2013 at 8:34
-
1→ Dark: I suggested do give it a shell of
/usr/bin/false
not a home. This is the standard way all_users
are configured on MacOS X. This doesn't prohibit any access throughsudo
. Check with:dscl
&sudo
on_sandbox
.– danJul 22, 2013 at 16:40