Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RHEL, su in /etc/profile

Posted on 2013-11-19
3
Medium Priority
?
230 Views
Last Modified: 2013-11-26
When I try to use su in a script,  I perform a whoami, followed by a su

[root@btvm1 etc]#
[root@btvm1 etc]# cat aa
whoami
su - mqm
[root@btvm1 etc]#
[root@btvm1 etc]#
[root@btvm1 etc]# ./aa
root
mqm
Password:

Open in new window


As you can see, he thinks he is root, but when he tries to perform the su, he thinks he needs a pw

What is going on, how can I convince root of his identity
0
Comment
Question by:Los Angeles1
3 Comments
 

Author Comment

by:Los Angeles1
ID: 39660852
ok I know I am slow, but in this case the password it was happy with was the root password

1> So the question is why if I am calling a batch file from root do I need to enter my root password

2> and, How can I fix this ?

Thanks
0
 
LVL 19

Expert Comment

by:xterm
ID: 39660897
Why are you running the batch file as root, and then trying to have it su to mqm.  Can you not just run it while logged in as user mqm?

If you are running it as root, but want it to execute a command as user mqm, then do it like this:

su mqm -c <command to run as mqm>


PS. I do not know why you are being prompted for a password in that script - I created the identical script on my system, and it changed users as it was supposed to.
0
 
LVL 21

Accepted Solution

by:
Mazdajai earned 2000 total points
ID: 39663600
You can do this with sudo.

Edit /etc/sudoers wit the following line -
<userid> ALL=(ALL)       NOPASSWD: ALL

Open in new window

sudo su - mqm -c command

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question