Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to automate one job in hudson, but hudson always uses the user hudson to run the scripts. What I want is to run the script as another user.

I've looked through ServerFault answers, but only found a solution that uses the su command, which requires me to type in target user's password. This will not work for automated scripts.

Could anyone help with this one? Thanks.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

You can use sudo to do this. First, you need to modify the /etc/sudoers file to add a rule that allows the hudson user to become the other user for the script in question. Let's assume you have a user1 account that needs to run /usr/local/bin/my_script.sh.

Run visudo to modify the sudoers file, and add a like like:

hudson ALL=(user1) NOPASSWD: /usr/local/bin/my_script.sh

Then, use the following sudo command to run the script from hudson:

sudo -u user1 /usr/local/bin/my_script.sh

It's very important that you use visudo to modify the sudoers file in order to check the file for errors before putting it in place. Also, I'd suggest a quick read through man sudoers in order to clearly understand what the above does before adding it to your configuration.

share|improve this answer
add comment

sudo -u hudson command will run command as user hudson. It needs to be setup in your sudoers file, where you can also configure it to not require a password.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.