Difference between "su" and "su -" ?

Difference between "su" and "su -" ?

Post by Arctic Stor » Tue, 13 Feb 2001 12:49:43



When I change to root super user, I usually issue the command
su -
And this has worked for me well.
What's the difference between "su -" and "su" for root super user?
 
 
 

Difference between "su" and "su -" ?

Post by cbbro.. » Tue, 13 Feb 2001 13:16:59



> When I change to root super user, I usually issue the command
> su -
> And this has worked for me well.
> What's the difference between "su -" and "su" for root super user?

The difference is that 'su' keeps data about the existing session as
the previous user, whilst 'su -' tries to provide an environment like
what would be produced if you had logged in directly as root.

An immediate visible difference would be with PWD.  Supposing you're
in /usr/src/linux, as your own ID, and then "su" to root.

-> 'su' would leave you in that same directory, with environment
   variables retaining a whole lot of the values that were set up in
   your user environment.

-> 'su -' puts you probably in directory /root, with the environment
   set from root's .bashrc setup and such...
--

http://vip.hyperusa.com/~cbbrowne/internet.html
"The cost of living has just gone up another dollar a quart."  
-- W.C. Fields

 
 
 

Difference between "su" and "su -" ?

Post by E J » Tue, 13 Feb 2001 13:03:18


su -  : You will inherit the root attributes from /root/.bash_profile
su      : You will still use the user's attributes from user's
$HOME/.bash_profile

> When I change to root super user, I usually issue the command
> su -
> And this has worked for me well.
> What's the difference between "su -" and "su" for root super user?

 
 
 

Difference between "su" and "su -" ?

Post by Nils O. Sel?sda » Tue, 13 Feb 2001 17:21:20




Quote:> When I change to root super user, I usually issue the command
> su -
> And this has worked for me well.
> What's the difference between "su -" and "su" for root super user?

man su
 -, -l, --login
        make the shell a login shell
 
 
 

Difference between "su" and "su -" ?

Post by Paul Colquho » Tue, 13 Feb 2001 20:17:53


|> When I change to root super user, I usually issue the command
|> su -
|> And this has worked for me well.
|> What's the difference between "su -" and "su" for root super user?
|
|The difference is that 'su' keeps data about the existing session as
|the previous user, whilst 'su -' tries to provide an environment like
|what would be produced if you had logged in directly as root.
|
|An immediate visible difference would be with PWD.  Supposing you're
|in /usr/src/linux, as your own ID, and then "su" to root.
|
|-> 'su' would leave you in that same directory, with environment
|   variables retaining a whole lot of the values that were set up in
|   your user environment.
|
|-> 'su -' puts you probably in directory /root, with the environment
|   set from root's .bashrc setup and such...

And it works for other users as well.

'su - fred' will get you fred's login environment while 'su fred'
wont.

--

Universal Life Church    http://andor.dropbear.id.au/~paulcol
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
xenaphobia: The fear of being beaten to a pulp by
            a leather-clad, New Zealand woman.

 
 
 

Difference between "su" and "su -" ?

Post by -ljl » Tue, 13 Feb 2001 22:54:17




Quote:> When I change to root super user, I usually issue the command
> su -
> And this has worked for me well.
> What's the difference between "su -" and "su" for root super user?

Logon using "su -" then type "pwd; echo $PATH".  Then logon using
"su" and repeat the two command sequence.

--
Louis-ljl-{ Louis J. LaBash, Jr. }

Sent via Deja.com
http://www.deja.com/

 
 
 

Difference between "su" and "su -" ?

Post by Floyd Davidso » Wed, 14 Feb 2001 00:54:03



>When I change to root super user, I usually issue the command
>su -
>And this has worked for me well.
>What's the difference between "su -" and "su" for root super user?

You are getting a number of responses, all of which are either
somewhat wrong or incomplete.  

Read the man page!  It says,

     The optional argument - may be used to provide an
     environment similiar to what the user would expect
     had the user logged in directly.

Specifically that means su will retain the environment of the
shell which invokes it, except when the - option is used and
then the environment will be the same as a login shell for the
user su'd to.

So when does it make a difference?  Well... maybe or maybe not in
several different situations.

Consider a large machine, where several different individuals
are responsible for various systems admin tasks.  Each of them
wants to work in their own customized environment of course, and
obviously the root login shell cannot be made suitable for all of
them.  Hence that root login shell might be a very bare bones
environment, and none of the admin users will ever use "su -" to
become root.  Instead they all use just "su", and retain their
own environment (which with a few tricks in the init files can
be changed somewhat when the user is root).

On a workstation with only one person accessing root, root can be
customized in one specific way, and "su -" would be very
convenient to switch between a normal userid and root.

Another example might be when a system admin is asked to trouble
shoot a problem for a user.  There is clearly no point in su'ing
to that user's account and running an errant program with the
environment being used by root, so using the - option will
provide the systems admin with an environment identical to the
user with a problem.

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

Difference between "su" and "su -" ?

Post by spi.. » Wed, 14 Feb 2001 21:51:38



Quote:> When I change to root super user, I usually issue the command
> su -
> And this has worked for me well.
> What's the difference between "su -" and "su" for root super user?

su changes user, and only user.
su - builds up the users environment (such as roots $PATH) and takes him
$HOME.
--
______________________________________________________________________________

|Andrew Halliwell BSc(hons)|                                                 |
|            in            | "I think so brain, but this time, you control   |
|     Computer Science     |  the Encounter suit, and I'll do the voice..."  |
------------------------------------------------------------------------------
 
 
 

Difference between "su" and "su -" ?

Post by Villy Kru » Thu, 15 Feb 2001 17:01:41


On Tue, 13 Feb 2001 12:51:38 +0000,


>> When I change to root super user, I usually issue the command
>> su -
>> And this has worked for me well.
>> What's the difference between "su -" and "su" for root super user?

>su changes user, and only user.
>su - builds up the users environment (such as roots $PATH) and takes him
>$HOME.

For people who grew up on System V notice that System V will change the
PATH allways whereas other systems such as Linux and AIX and likely also
BSD will keep the PATH intact when doing 'su' without the dash.  

Villy