Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I get my environment to come along when I "su"?

A reader writes:
Here is the problem - when I su to become root I don't have any aliases or any stuff in my path. I also am not sure were the .bash_profile for root goes and if it is even read when su'ing - please help thanks.

Dave's Answer: This is an interesting puzzle. By default, when you use the sudo command, your environment should travel with you since it's just changing the effective user ID (or euid, if you want to be really geeky!). But su is another beast because it spawns a new subshell that should appear like it's from that account, not you. So shell aliases and environment settings are not typically inherited properly. Usually, though, people who work with su use either su - acct or su -l acct (depending on what flavor of Unix) which makes the subshell act as if it were a login shell, sourcing all "rc" files, and similar. That's probably what you want to use in this case.

In terms of where root has its "rc" files, the best way to ascertain that is to identify the HOME directory for the root account by using grep:

grep root /etc/passwd
Quite often, root has its home in the directory / or, sometimes, /home/root. You could then easily copy all of your own "rc" files into that directory to ensure that your root environment is functionally identical.


Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

How do I get my enviroment to change back to my previous enviroment.

Posted by: TIMOTHY at August 15, 2005 4:57 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]