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

My script, when executed as root, uses the sudo without passwd, and that is fine. Sometimes however, I must execute that script as an ordinary user, which "switches" to itself by that sudo command. I must omit the passwd procedure in this case also.

Currently I use the default (almost empty) sudoers file. I'd like to extend it with a simple, general, not user-specific rule for the above.

I tried to setup some wildcard rules with * and ALL, but failed.

Thank you for your help.

share|improve this question

migrated from Jun 13 '12 at 7:08

This question came from our site for professional and enthusiast programmers.

Say that the user that must execute the script is someuser, the full path to the script is /usr/local/bin/somescript.

Using visudo, add the following line

someuser ALL=(someuser) NOPASSWD: /usr/local/bin/somescript

To execute this (you can omit the full path if the script is in the $PATH:

someuser@somehost:~$ sudo -u someuser /usr/local/bin/somescript

But... there's any reason why you can't execute the command without sudo? There shouldn't be any difference calling it sudo'ed this way or just without sudo


If you need to allow all users to execute any command as any user, put the following line (but take into account that this is a TOTALLY INSECURE AND RISKY configuration. This would allow any user (first column) to execute on any machine (non-important, 2nd column) any command(fourth column) as any user (third column, between parentheses))

share|improve this answer
"There shouldn't be any difference calling it sudo'ed this way or just without sudo" You are right. But I have to use the script 'as is' – stoqlt Jun 11 '12 at 22:32
Thanks Carlos, your suggestion seems to be correct, and I will use it if I cannot find a less explicit solution. However, I am looking for a less specialized config. For all users. For all commands. Nothing specific, just the "No difference" phenomenon mentioned above. – stoqlt Jun 11 '12 at 22:40
I'd like to specify something like (%Myself) or (%Sameuser) in the parantheses. Then NOPASSWD: would do its job. – stoqlt Jun 13 '12 at 1:17

You want to execute a script that will run as root, but allow non-privileged users to run it. This means you should enable the setuid bit.

share|improve this answer
scripts cannot use the setuid bit usually, as the interpreter ignores them upon reading the script. – Carlos Campderrós Jun 12 '12 at 12:56

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.