Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RHEL, su in /etc/profile

Posted on 2013-11-19
3
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

722 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