Why use "su -" rather than "su"

Rick Stevens rstevens at vitalstream.com
Fri Jul 15 17:03:00 UTC 2005


David Gavin wrote:
> On Fri, July 15, 2005 12:33, Rick Stevens said:
> 
>>Mike McCarty wrote:
>>
>>>Paul Howarth wrote:
>>>
>>>
>>>>Mike McCarty wrote:
>>>>
>>>>
>>>>>I have a general *NIX admin question. Why does one want to use
>>>>>su -
>>>>>as opposed to just su? I think I understand the difference in regards
>>>>>to "su -" actually changes you to root, as if logged in that way, as
>>>>>opposed to simply granting root privilege. But why do that? If I do
>>>>>that, then I lose my path settings, and can't run my normal editor,
>>>>>which
>>>>>is in ~/bin and so on. I just use "su".
>>>>>
>>>>>What am I missing?
>>>>
>>>>
>>>>
>>>>You're missing getting /sbin and /usr/sbin on your PATH, which you
>>>>probably want for what you're about to do as root. If you already have
>>>>those directories on your regular user's PATH (which is not the
>>>>default), "su -" probably doesn't help you much. But it does for most
>>>>people.
>>>>
>>>>Paul.
>>>>
>>>
>>>Hmm. So I give up my regular editor in return for not having to type
>>>/sbin/
>>>
>>>Well, I think I'll go along the way I am. I'm a pretty good typist.
>>>
>>>I thought there might be a *real* reason, and I had missed something. I
>>>was wondering if there might be some subtle problems which would bite
>>>me later.
>>
>>Actually, "su" will give you root's UID and GID, but not root's
>>_environment_ (path and such).  "su -" is roughly equivalent to doing
>>a full-on login as root, and thus getting not only the UID and GID, but
>>the environment as well.
>>
>>See "man su" for details.
> 
> <SNIP>
> 
> 
>  "su -" also repositions you into root's home directory, which may not be
> what you wanted.

Correct.  I assumed (probably a bad idea) that my "...login as root"
comment would infer that and that the reader would understand.
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-  Time: Nature's way of keeping everything from happening at once.  -
----------------------------------------------------------------------




More information about the fedora-list mailing list