LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2011, 01:40 AM   #1
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Rep: Reputation: 1
Lightbulb 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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-23-2011, 01:54 AM   #2
rishipandit007
Member
 
Registered: Oct 2006
Distribution: Debian, Ubuntu, Centos
Posts: 36

Rep: Reputation: 17
Hi

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


Nitin
 
Old 06-23-2011, 01:55 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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"

Last edited by acid_kewpie; 06-23-2011 at 01:58 AM.
 
Old 06-24-2011, 12:07 AM   #4
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
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.
 
Old 06-24-2011, 12:30 AM   #5
bonixavier
Member
 
Registered: Sep 2010
Distribution: Slackware
Posts: 320

Rep: Reputation: 69
Quote:
Originally Posted by acid_kewpie View Post
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?
 
Old 06-24-2011, 01:25 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by aggrishabh View Post
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.
 
Old 06-24-2011, 01:40 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by bonixavier View Post
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.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Howto? limited, secure, interactive shell (with sudo on RHEL). Impossible? QuantSuff Linux - Security 1 08-09-2010 05:45 PM
Can't use sudo, only account that's not root is not a sudo'ers [Ubuntu 9.10] randyriver10 Linux - Desktop 1 01-09-2010 07:56 PM
Need Suggestions on Sudo on RHEL 5 coolinux Linux - Newbie 4 10-11-2009 07:33 PM
Sudo upgrade for RHEL to support Ldap ciphyre Red Hat 6 12-08-2008 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration