Sign up ×
Server Fault is a question and answer site for 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?


share|improve this question

2 Answers 2

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/

Then, get your script to execute:

sudo -u userTheScriptShouldRunAs /home/userTheScriptShouldRunAs/
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 – Telium Feb 17 '13 at 5:04

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

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.