Operating System - HP-UX
1836492 Members
2495 Online
110101 Solutions
New Discussion

Re: su - user2 and su user2

 
Hanry Zhou
Super Advisor

su - user2 and su user2

Hi,

In both situation of
user1#> su - user2 and
user1#> su user2


I have following questions:
1) if user1's the environment will be inherited in user2, including .profile, and all environment variables.
2) if user2's environment will be executed.

thanks in advance.
Roger
none
4 REPLIES 4
Sandip Ghosh
Honored Contributor

Re: su - user2 and su user2

when U do su - user2
it will inherit the environment of user2
but whet U do su user2
the environment will be as defined in the user1 profile.

Sandip
Good Luck!!!
Jeff Schussele
Honored Contributor

Re: su - user2 and su user2

Hi Roger,

In the first scenario - Yes
In the second - No.

The "-" forces the env inheritance. Without the "-" user1 retains it's env & just "becomes" user2.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
S.K. Chan
Honored Contributor

Re: su - user2 and su user2

a) user1#> su - user2 and
b) user1#> su user2
1) if user1's the environment will be inherited in user2, including .profile, and all environment variables.
==> No for a); Yes for b)
2) if user2's environment will be executed.
==> Yes for a); No for b)

Tom Dawson
Regular Advisor

Re: su - user2 and su user2

Roger,

This may be just a matter of semantics, but...

From the "su" man page ( v10.20 ):

... su executes a new shell with the real and effective user ID,
real and effective group ID, and group access list set to that
of the specified user.
The new shell is the one specified in the shell field of the new
user's entry in the password file, /etc/passwd. su uses the Bourne
shell (see sh-bourne(1)).
The arguments (the balance of the command line after username) are
passed along to the new shell for execution, permitting you to run
shell procedures with the new user's privileges.

When you exit from the new shell, the previous user name and
environment are restored.

If you specify the - option of the su command, the new shell starts up
as if you just logged in.
---------------------------------

So, with the "su -" option, there is no "inheritance" going on. You are creating a completely new shell. If, as user1, you assign a value to MYVAR, then "su - user2", the user2 environment will not have a MYVAR environment variable.

HTH,
Tom