Create a user to run the daemon on MacOS X?

What is the correct way to create a user on MacOS X from the command line that will only be used to run an application with multiple applications? For example, the user "_www" already exists for Apache httpd, but for the new application, I want him to use his own account.

+5
source share
1 answer

There is no adduser command. Mac's approach is to use the dscl command, which is the "Directory Service Command Line Utility." Directory services are similar to LDAP, but this is a different solution.

The examples below will use "mydaemon" as the intended account, although you usually use a value that matches the name of your daemon application.

All daemon users have an underscore prefix, such as _www.

To list the attributes of an existing record:

sudo dscl . -read /Users/_www 

Before creating a user, create a group in which you select an unused group identifier (here we selected 300):

  sudo dscl . -create /Groups/_mydaemon sudo dscl . -create /Groups/_mydaemon PrimaryGroupID 300 

After that, we create a new user (we use the same identifier as for the group that will not use the shell:

  sudo dscl . -create /Users/_mydaemon UniqueID 300 sudo dscl . -create /Users/_mydaemon PrimaryGroupID 300 sudo dscl . -create /Users/_mydaemon UserShell /usr/bin/false 

The above is based on reading from different sources of information and checking the process yourself. One of the links I found useful is:

http://minecraft.gamepedia.com/Tutorials/Create_a_Mac_OS_X_startup_daemon

Note. There is also a version of the dscl GUI (location based on MacOS X 10.10):

/System/Library/CoreServices/Applications/Directory\Utility.app/

+7
source

Source: https://habr.com/ru/post/1232408/


All Articles