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:
- How can I create an _www like user for a daemon, without home directory i.e.
- How can I run a script as this new user.
Thanks for help!
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.
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
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