Solved

RHEL, su in /etc/profile

Posted on 2013-11-19
3
206 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 500 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now