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.

So I'm currently trying to create a sudoers file, but I ran into something I can't figure out.

The end result I'm looking for is that I want users to be able to do something like:

sudo /usr/sbin/script.pl

But, instead of running as root, I'd like the script to run as "other_user".

I looked into the sudoers file, and I tried adding a line like:

pedro      ALL = (other_user) /usr/sbin/script.pl

But that only works if I specify the user by doing sudo -u other_user /usr/sbin/script.

Is there an (easy) way to have the script run as a specific user, without having to specify it in the command line?

share|improve this question
5  
Just curious why -u is too much work? –  MDMarra Jun 21 '12 at 21:02
1  
I'm actually porting a (huge) Solaris RBAC configuration to Red Hat. Solaris allows you to simply do "pfexec <command>", and if you have permission to, it'll run <command> as whatever user you've specified in the config file. I guess the situation is that I personally don't care to use -u, but there are a bunch of scripts that would need to be picked through and modified, since instead of just replacing pfexec with sudo, every script would have to be modified to specify the particular user that is required for the different commands. :/ –  Pedro Jun 21 '12 at 21:30
    
To be fair sudo != pfexec –  Iain Jun 21 '12 at 21:44
    
Have the script start by switching users (or write a wrapper script that does that, then calls the actual script). You sudo to root, the script sudos to the user (it can, since it is root) and all is good. –  Konerak Jun 22 '12 at 7:04

3 Answers 3

I don't think there is a configuration parameter to do this. You could hack the source code and recompile it. You could also use an alias e.g.

alias sudo='sudo -u pedro'

but then you'd have to remember to out a \ infront of sudo for anything else

\sudo somecommand 
share|improve this answer
1  
+1 for escaping an aliased command –  Jeff Ferland Jun 21 '12 at 21:41

here is something that might work:

alias sudop='sudo -u pedro'
alias sudoa='sudo -u alice'

You still have to specify something in addition to sudo, but it is deeply concatenated and flows pretty easily to type. I use a variation of this for common sudo commands I need to run.

share|improve this answer

Do sudo chown other_user /usr/sbin/script; sudo chmod 6777 This will change the owner of the script to other_user, then set it as editable and executable by all, and finally set it to run as other_user.

sudo chown other_user /usr/sbin/script; sudo chmod 6555 //same as above but read-only sudo chown other_user /usr/sbin/script; sudo chmod 6755 //same as 6777 but can only be edited by other_user

See man chmod and man chown for more details

share|improve this answer

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.