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 have a simple bash script which runs great as a regular user. When launched from postfix, it runs as nobody:nobody which prevents many commands from working.

Is it possible for the script to change to another user account while running, to allow these other programs to run?

Thanks

share|improve this question
1  
add comment

2 Answers

up vote 1 down vote accepted

You will need to configure sudo so that you can run a specific command as nobody which will run as another user.

Typically, something like (in your sudoers file):

nobody ALL=(userTheScriptShouldRunAs) NOPASSWD: /home/userTheScriptShouldRunAs/test.sh

Then, get your script to execute:

sudo -u userTheScriptShouldRunAs /home/userTheScriptShouldRunAs/test.sh
share|improve this answer
    
I think this is the only way...I don't like to sudo a script callable from a mail message but no option. Thanks –  Michelle Feb 17 '13 at 5:04
add comment

You can set a program's permissions with the setuid bit:

chown usertorunas filename

chmod ug+s filename

That will make it run as the user who owns the file.

However, as @Jay reminded me, it doesn't work for scripts. To run a script as a different user you need to make a small program as explained here which CAN be setuid, and calls your script.

share|improve this answer
    
You can't set setuid bits on scripts, too much of a security risk. –  Jay Feb 16 '13 at 22:59
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.