Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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).
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.