LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What's the difference between su - & su ? (https://www.linuxquestions.org/questions/linux-newbie-8/what%27s-the-difference-between-su-and-su-347775/)

Thaidog 07-28-2005 03:16 PM

What's the difference between su - & su ?
 
What is the difference with the su - option to root rather than the plain old su option?

Matir 07-28-2005 03:19 PM

'su -' reads in the root environment (/root/.bash_profile, etc.) as if you'd logged in as root. This is commonly needed to have /usr/sbin and /sbin included in your PATH. 'su' does not do this, and only elevates your privileges.

Thaidog 07-28-2005 03:21 PM

Quote:

Originally posted by Matir
'su -' reads in the root environment (/root/.bash_profile, etc.) as if you'd logged in as root. This is commonly needed to have /usr/sbin and /sbin included in your PATH. 'su' does not do this, and only elevates your privileges.
thx... exaclty what I needed!

Matir 07-28-2005 03:25 PM

No problem. While it IS a matter, of preference, I always use su -. In fact, when I really need to be root, I have an alias that does 'sudo su -'.
Code:

alias rootme='sudo su -'
That was, btw, an idea stolen from the Knoppix LiveCD. (The name rootme).

jrdioko 07-28-2005 03:41 PM

Why "sudo su -" instead of "su -"? Just curious...

I used to use "su -" instead of "su", but when I'm su'ing in the first place it's usually because I need to do something with root permissions in the current directory, and it scares me that "su -" takes you away from that directory to /root. It seems to easy to wipe out root's home with a stray rm command, or worse something else if that rm command had a ".." in it.

Matir 07-28-2005 03:45 PM

Well, 'su -' gives you (as I said) the environment of root... it makes it a login shell. I use sudo so I don't have to type my (very long) root password all the time. It caches and uses my own password (or you could have it not require any password). It really seems to me to just be a matter of personal preference.

jrdioko 07-28-2005 03:49 PM

I see. Just don't forget that very long root password :)

Matir 07-28-2005 03:58 PM

Haven't forgotten it yet... knock on wood. Now, the passwords to all my email accounts.... that's a different matter.


All times are GMT -5. The time now is 09:32 PM.