Operating System - Linux
1831357 Members
2954 Online
110024 Solutions
New Discussion

Re: su - userid & su userid

 
Hanry Zhou
Super Advisor

su - userid & su userid

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
2 REPLIES 2
Vernon Brown_2
Frequent Advisor

Re: su - userid & su userid

User#2 will inherit User1 environment. You can override this by using the -l switch. Example:
su -l
Will make user#2 run its environment shell.
Mark Fenton
Esteemed Contributor

Re: su - userid & su userid

$ su - username

invokes username's login shell

$ su username

does not invoke login shell, just changes the effective UID of the user.

Quoting from man su
"Change the effective user id and group id to that of USER.

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

-c, --commmand=COMMAND
pass a single COMMAND to the shell with -c

-f, --fast
pass -f to the shell (for csh or tcsh)

-m, --preserve-environment
do not reset environment variables

-p same as -m

-s, --shell=SHELL
run SHELL if /etc/shells allows it

--help display this help and exit

--version
output version information and exit

A mere - implies -l. If USER not given, assume root."