Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 9 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/

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

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

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

sudo -u user1 /usr/local/bin/

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

Commenting the Defaults requiretty entry in /etc/sudoers or other included suders files should help.

As for the perl error - your're probably using a different PERL5LIB or a different perl binary for that user - and that won't get passed in sudo (unless you use -E or env_keep). Check your environment and possibly, permissions.

share|improve this answer

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

Your Answer


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.