Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
When using su , a sub shell is started. This is an environment where you are able to work as the target user account, but environment settings for that user account have not been set. If you need complete access to the entire environment of the target user account, you can use su - to start a login shell. If you start a login shell, all scripts that make up the user environment are processed, which makes you work in an environment that is exactly the same as when logging in as that user.
thats all fine,and i understand it...
but when would you want to login with the complete user environment,and when wouldnt you?
is it more to do with bash scripting and testing things?
Hum...
I always kinda, sorta assumed the su - form was expressly to let you use your accounts locally defined environment variables. Back in the days of HP and Sun workstations, that seemed like reason enuf.
Use "su" when you're currently doing something that temporarily needs root permission, eg: you just ran make and now need to run make install. "su" will leave your environment and working directory alone so you can simply run "make install" after the su, without having to cd all over the place and possibly copy/paste any necessary environment variable declarations for the build to work correctly.
Use "su -" when you need to do a task as root that has nothing to do with what you've been doing previously in the terminal, in which having a clean shell with root's proper PATH and other environment variables would be beneficial (eg: /sbin and /usr/sbin are usually not in regular users' PATH, so you want to use "su -" to load up root's full environment to have access to those programs).
Last edited by suicidaleggroll; 08-08-2016 at 12:09 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.