LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to get root user PATH from normal user (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-root-user-path-from-normal-user-898907/)

nagendrar 08-23-2011 03:36 AM

How to get root user PATH from normal user
 
Please help me to get root user PATH from normal user in linux.

ThanQ,
Nagendra

0men 08-23-2011 04:03 AM

Well you could use sudo :)
or if you know about sudo and it's still not working. Try this

For example let's say you want to shut down your machine.

If you use ubuntu or mint etc you would use
sudo shutdown now -h

However if you try that command and you grt an error message such as "command not found"
you'll have to specify where shutdown is. (it's in Sbin )

So you would use instead
sudo /sbin/shutdown now -h

I'm guessing your using debian or slack though

I hope this helps :S

Kind regards

nagendrar 08-23-2011 04:14 AM

I did like below. But I got same as non-root user. So I think, it is difficult to get PATH of root user from non-root user using 'sudo'.

[nag@nag collector]$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/nag/bin
[nag@nag collector]$ sudo echo $PATH
Password:
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/nag/bin
[nag@nag collector]$

Please help me to solve this.

kostya 08-23-2011 04:19 AM

Deleted as soon as I noticed my misunderstanding of the question.

The command `sudo su` must log you in as root, then do `echo $PATH` to see the root's path.
That would mean your sudo policy allows you to have root access to your machine, in which case I don't see why you can't just login as root and see the path.

(On the other hand, if you arent' given such access to the machine, then why should anyone help you to violate the machine owner's policy? That's about the size of it.)

millgates 08-23-2011 04:24 AM

Hi, $PATH is the environment variable -- each terminal can have its own. You can have multiple terminals open and have different $PATH in each of them. If you want to know root's default path, you need to login as root:
$ su -
if you are not root, you can grep /etc/profile.d for PATH and /root/.bash_profile and /root/.bashrc, but you won't probably have permission to read them

nagendrar 08-23-2011 04:37 AM

We able to get PATH env from /root/.bash_profile using sudo as below. But we won't get total extendable PATH like PATH=/usr/bin:/usr/sbin:/sbin/:.....

[nag@nag ~]$ sudo grep PATH= /root/.bash_profile
PATH=$PATH:$HOME/bin

Please help me solve this.

Regards,
Nagendra

kostya 08-23-2011 04:43 AM

Quote:

Originally Posted by kostya (Post 4450922)
...
The command `sudo su` must log you in as root, then do `echo $PATH` to see the root's path.

What, the above didn't work for you?

scottro11 08-23-2011 04:45 AM

Note that you should mention what distribution you're using.

I suspect you're using a RedHat based one. I have a page on this, as the question used to always come up on Fedora forums at

http://home.roadrunner.com/~computer...su/rhpath.html

I think the instructions there should help.

nagendrar 08-23-2011 04:53 AM

i did like below. But i did not get anything out put because terminal changed.

[nag@nag Downloads]$ sudo su;echo $PATH
[root@nag Downloads]#


Here i need to do without login as root. Please help me solve this.

Regards.
Nagendra

---------- Post added 08-23-11 at 03:24 PM ----------

I am using CentOS 5

ThanQ,
Nagendra

jdkaye 08-23-2011 04:57 AM

Is this homework? If not why do you want to do this? :confused:
jdk

MTK358 08-23-2011 05:01 PM

Quote:

[nag@nag Downloads]$ sudo su;echo $PATH
[root@nag Downloads]#
That's wrong. You're running "sudo su", then once you exit the shell created by "su", the command "echo $PATH" will be run in your original shell.

Do it like this:

Code:

$ sudo su
# echo $PATH


chrism01 08-23-2011 08:40 PM

When you use su, you must specify '-' to get root user's env, otherwise you are logged in as root, but with you orig env.
http://linux.die.net/man/1/su

What you get via sudo depends on the content of the sudoers file http://linux.die.net/man/5/sudoers


All times are GMT -5. The time now is 07:09 PM.