LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-26-2005, 04:43 PM   #1
J--Lew
LQ Newbie
 
Registered: Aug 2005
Location: Calgary, Canada
Posts: 29

Rep: Reputation: 15
$PATH changes after logging in as root?


Hey guys, I don't know if this is strange or not, but I couldn't seem to find it posted anywhere else on this forum. What happens is when I start a terminal session, everything is fine. But then after I log in as root, and then back to a regular user, my entire $PATH variable has changed:

Code:
jlewis@linux:~> echo $PATH
/home/jlewis/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/jvm/jre/bin
jlewis@linux:~> su
Password:
linux:/home/jlewis # echo $PATH
/usr/sbin:/bin:/usr/bin:/sbin:/usr/X11R6/bin
linux:/home/jlewis # su jlewis
jlewis@linux:~> echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
It seems as if after I log back as jlewis, the root user's $PATH is carried over.

any ideas?

Thanks guys
 
Old 09-26-2005, 04:49 PM   #2
free_ouyo
Member
 
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133

Rep: Reputation: 15
$PATH changes after logging in as root?

Hello,

jlewis@linux:~> echo $PATH
/home/jlewis/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/jvm/jre/bin
=> Normal user $PATH

jlewis@linux:~> su
Password:
linux:/home/jlewis # echo $PATH
/usr/sbin:/bin:/usr/bin:/sbin:/usr/X11R6/bin
=> root with su $PATH

linux:/home/jlewis # su jlewis
jlewis@linux:~> echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
=> user $PATH with su

exit from 'su jlewis' ,exit from 'su root' and the $PATH should be the original.
--
free_ouyo
 
Old 09-26-2005, 04:56 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,793

Rep: Reputation: 292Reputation: 292Reputation: 292
When you su to root you get the su PATH, not the root PATH. When you su to jlewis you get the su PATH, not the jlewis PATH. When you exit from su you go back to the PATH you had before you called su. That is the logic behind free_ouyo's explanation of how to get back to the jlewis PATH.

------------------------
Steve Stites
 
Old 09-26-2005, 05:05 PM   #4
J--Lew
LQ Newbie
 
Registered: Aug 2005
Location: Calgary, Canada
Posts: 29

Original Poster
Rep: Reputation: 15
Ok thanks guys that was a lot simpler than I assumed!

Thanks again!
 
Old 09-26-2005, 10:15 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If you use 'su -', the '-' tells it to log you in as that user INCLUDING the user's normal login environment ie it'll use his .bash_profile, .bashrc files.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I retain the PATH in the root account even when I switch to root using su? thearchitect Linux - Newbie 1 08-13-2005 01:02 AM
exporting PATH (without logging in again) rohr Debian 1 02-17-2005 11:56 AM
Logging in to Root NathanCohen2003 Linux - Software 3 07-10-2004 05:11 PM
Logging on as Root Iain Wilson Linux - Newbie 7 09-16-2003 03:23 AM
using red-carpet without logging out and logging as root. packman Linux - Software 1 12-09-2002 03:55 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration