LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SUDO help RHEL 5* (https://www.linuxquestions.org/questions/linux-newbie-8/sudo-help-rhel-5%2A-887874/)

aggrishabh 06-23-2011 01:40 AM

SUDO help RHEL 5*
 
Hi All,

Please read th below scenario

1) two users abc and xyz.
2) user abc have sudo permission to access xyz's account without password.
3) now user abc need to run a script resides in his home directory. script may be like this

#!/bin/bash
sudo su - xyz
ls -ltr


just to show the files in the xyz's home directory.
is it possible to do so? if yes, then how.


Thanks in advance.

rishipandit007 06-23-2011 01:54 AM

Hi

Try sudo /bin/sh -c "cd /home/xyz; ls -ltr"


Nitin

acid_kewpie 06-23-2011 01:55 AM

this looks a hell of a lot like homework, but ok...

DON'T DO "sudo su -" IT IS AN EVIL HACK THAT IS NOT NEEDED ANYMORE. NEVER DO IT. Do "sudo -i" instead. Just run "sudo -i -u xyz ls -ltr"

aggrishabh 06-24-2011 12:07 AM

Thanks for your inputs.

Hi Moderator this is not a homework.;)

sadely this didn't solve my purpose. As i clearly mentioned above that this all should be in a shell script(point 3) (i just gave a example there) and i need to run this script from user abc to extract information (file etc.) that resides in user xyz home directory.(i exactly didn't want ll -tr result that was just for the example).

conditions
only sudo access is allow to user xyz.

bonixavier 06-24-2011 12:30 AM

Quote:

Originally Posted by acid_kewpie (Post 4393458)
DON'T DO "sudo su -" IT IS AN EVIL HACK THAT IS NOT NEEDED ANYMORE. NEVER DO IT.

I don't use sudo much but, for what I understand, both su - and -i will get you a clean login shell, won't they? What does -i have that is superior to su - and what kind of dangers does running sudo su - bring to your system that make you say NEVER DO IT?

acid_kewpie 06-24-2011 01:25 AM

Quote:

Originally Posted by aggrishabh (Post 4394250)
Thanks for your inputs.

Hi Moderator this is not a homework.;)

sadely this didn't solve my purpose. As i clearly mentioned above that this all should be in a shell script(point 3) (i just gave a example there) and i need to run this script from user abc to extract information (file etc.) that resides in user xyz home directory.(i exactly didn't want ll -tr result that was just for the example).

conditions
only sudo access is allow to user xyz.

If you are going to put arbitrary conditions on a task then that really proves it's homework. When you ask for help it is more than reasonable to be given the best and most reasonable solution, not one with conditions and shortcomings attached. If that was just an example then it was unrepresentative, and a bad example.

acid_kewpie 06-24-2011 01:40 AM

Quote:

Originally Posted by bonixavier (Post 4394262)
I don't use sudo much but, for what I understand, both su - and -i will get you a clean login shell, won't they? What does -i have that is superior to su - and what kind of dangers does running sudo su - bring to your system that make you say NEVER DO IT?

sudo su - runs su inside sudo. It spawns two logins and su has no concept of sudo itself. sudo -i formally opens a login shell session within sudo. It then has awareness that it is a sudo session, providing extra environmental variables like $SUDO_USER which provides ways to audit and account for the actions that occur within the session, whch su is oblivious to. And sudo su - is a hack too. Since the -i flag was added (it's in RHEL5 but not RHEL4) there is no need to work around and trick your way into a shell when you can do it properly.


All times are GMT -5. The time now is 06:59 PM.