LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 03: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, 03:56 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,338

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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, 04: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, 09:15 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 12:02 AM
exporting PATH (without logging in again) rohr Debian 1 02-17-2005 10:56 AM
Logging in to Root NathanCohen2003 Linux - Software 3 07-10-2004 04:11 PM
Logging on as Root Iain Wilson Linux - Newbie 7 09-16-2003 02:23 AM
using red-carpet without logging out and logging as root. packman Linux - Software 1 12-09-2002 02:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 AM.

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
Open Source Consulting | Domain Registration