Run daemon as another user on mac os x

折月煮酒 提交于 2019-12-22 10:53:58

问题


I'm trying right now to create separate user for jenkins on Mac Os and run it with this user. I've created a new user:

# Create the group
sudo dscl . create /Groups/jenkins
sudo dscl . create /Groups/jenkins PrimaryGroupID 300
# Create the user
sudo dscl . create /Users/jenkins
sudo dscl . create /Users/jenkins PrimaryGroupID 300
sudo dscl . create /Users/jenkins UniqueID 300
sudo dscl . create /Users/jenkins UserShell /bin/bash
# Set the users pasword
sudo dscl . passwd /Users/jenkins 123qweASD
# Add the user to the group
sudo dscl . append /Groups/jenkins GroupMembership jenkins

And the I try to run jenkins as jenkins user:

sudo su - jenkins -c run_jenkins.sh

and got an error:

su: no directory

after I created directory for jenkins user:

sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins

followed next error:

su: unknown login: jenkins

General quiestion:

  1. How can I create an _www like user for a daemon, without home directory i.e.
  2. How can I run a script as this new user.

Thanks for help!


回答1:


man launchd.plist

 UserName <string>
 This optional key specifies the user to run the job as. This key is only
 applicable when launchd is running as root.

 GroupName <string>
 This optional key specifies the group to run the job as. This key is only
 applicable when launchd is running as root. If UserName is set and Group-
 Name is not, the the group will be set to the default group of the user.



回答2:


You may need to use the absolute of run_jenkins.sh (assuming its /Users/jenkins/run_jenkins.sh):

sudo su - jenkins -c /Users/jenkins/run_jenkins.sh



回答3:


su - emulates a normal login, and hence requires that the account be set up for regular logins (have a shell and home directory defined, etc). Unless you need this for some reason, just let sudo do it:

sudo -u jenkins run_jenkins.sh


来源:https://stackoverflow.com/questions/7984657/run-daemon-as-another-user-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!