Diff Between "su" and "su -" (superuser.com)

Published:   November 17, 2021

Bookmark for: https://superuser.com/questions/453988/whats-the-difference-between-su-with-and-without-hyphen

Keeping here for reference:

The difference between “-” and “no hyphen” is

Thus, it is advisable that administrative users, as well as any other users that are authorized to use su (and it is suggested that there be very few, if any) acquire the habit of always running the su command with the -l/–login option.


The hyphen has two effects:

1) switches from the current directory to the home directory of the new user (e.g., to /root in the case of the root user) by logging in as that user

2) changes the environmental variables to those of the new user as dictated by their ~/.bashrc. That is, if the first argument to su is a hyphen, the current directory and environment will be changed to what would be expected if the new user had actually logged on to a new session (rather than just taking over an existing session).


< Prev   Further Reading   Next >

For feedbacks: email@murarisumit.in