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.

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
add comment

migrated from stackoverflow.com Jun 13 '12 at 7:08

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

2 Answers

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

update

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))

ALL ALL=(ALL) ALL
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
add comment

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
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.