using sudo to execute script as another user

Matthew Hannigan mlh at zip.com.au
Tue Aug 27 06:53:13 EDT 2002


Simon Jespersen wrote:

> I want to execute a script from user "bb" as user "el" with el 
> environment. When i do sudo -u el -s /opt/script/myscript.pl the script 
> execute alright but it fails duo to the wrong invironment.
>  
> if i do su - el -c /opt/script/myscript.pl from bb it works fine but 
> promts me for passwd.
> 

You have to put the "su - el -c ..." in sudoers, so that you then do 
this fomr the command line:

  sudo su - el -c /opt/script/myscript.pl

i.e. you don't use the RunAs feature at all.  You could add
a NOPASSWD option for this in the sudoers file of course, if
you so desired.

It would be a nice enhancement of sudo to have a 'su -' equivalent
for the runas user.


Matt








More information about the sudo-users mailing list