1834154 Members
2646 Online
110064 Solutions
New Discussion

My profile

 
SOLVED
Go to solution
Qcheck
Super Advisor

My profile

I have my own profile, when I su to root still I want to use my own profile not the root's. [I know if I use su -, then I am using root's profile.] So whenever I su, the variables are resetting. How can I avoid this?
10 REPLIES 10
Adam W.
Valued Contributor

Re: My profile

The easiest way would be to copy your profile to the root account. Are you the only SA?
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: My profile

Hi:

# su root

...without the '-'

Regards!

...JRF...
Qcheck
Super Advisor

Re: My profile

No Adam, I don't want to do that. there are other admins.
Adam W.
Valued Contributor

Re: My profile

That is why I asked if you were the only one.

James, good to know. I was not aware of that.
There are two types of people in the world, Marines and those who wish they were.
Qcheck
Super Advisor

Re: My profile

That is what I am doing James. I know if I do su - then I am using root's profile. But I expect to use my profile when I just su. But still my profile is not working. When I did man on su, it says it will reset the variables, wheich I don't want to do. I should be able to list type all the root commands, show my PS1 variable and can do "esc k" to recall my previous commands.
Michael Mike Reaser
Valued Contributor

Re: My profile

Which variables are resetting? The su(1) man page states that if you're su'ing to root with*OUT* a "-", then PATH and PS1 are set to default values while HOME, ENV, LD_PRELOAD, LD_LIBRARY_PATH and SHLIB_PATH are deleted and all other variables are kept.

Maybe you should look at "man 4 security" for how to set up the /etc/default/security file on your system? That might allow you to keep most, if not all, of the variables that you're current seeing reset.
There's no place like 127.0.0.1

HP-Server-Literate since 1979
Patrick Wallek
Honored Contributor
Solution

Re: My profile

Why not just source your own profile after you su.

$ su - root
# . /home/username/.profile

Now you are using your profile again.
Qcheck
Super Advisor

Re: My profile

Thank you patrick. That is working, but how can I avoid typing/running my profile everytime I login? I want to run my profile as soon as I su . And when I su - then ot should use root's profile.
OldSchool
Honored Contributor

Re: My profile

if you are willing to modify root's .profile, you should be able to leverage the "who" command to automate this. Something like

olduser=`who am i | awk 'print {$1}'`
if [ $olduser = '' ]
then
. /home//.profile
fi

"who am i" will return your original login, so you can source your profile, and the other admins won't get those changes
Qcheck
Super Advisor

Re: My profile

Thank you all for all your time and help.