Solved

RHEL, su in /etc/profile

Posted on 2013-11-19
3
214 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

820 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