3

我现在正在尝试在 Mac Os 上为 jenkins 创建单独的用户并使用该用户运行它。我创建了一个新用户:

# 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

我尝试以 jenkins 用户身份运行 jenkins:

sudo su - jenkins -c run_jenkins.sh

并得到一个错误:

su: no directory

在我为 jenkins 用户创建目录之后:

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

跟随下一个错误:

su: unknown login: jenkins

一般问题:

  1. 如何在没有主目录的情况下为守护进程创建 _www 类用户,即
  2. 我如何以这个新用户的身份运行脚本。

感谢帮助!

4

3 回答 3

8

人启动d.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.
于 2011-11-03T18:52:14.363 回答
1

您可能需要使用绝对值run_jenkins.sh(假设它的/Users/jenkins/run_jenkins.sh):

sudo su - jenkins -c /Users/jenkins/run_jenkins.sh
于 2011-11-02T17:49:57.983 回答
0

su -模拟正常登录,因此需要为常规登录设置帐户(定义 shell 和主目录等)。除非你出于某种原因需要这个,否则就让 sudo 来做吧:

sudo -u jenkins run_jenkins.sh
于 2011-11-02T19:37:39.767 回答