Diff Between "su" and "su -"


Published:   November 17, 2021

Tags:
Ref: 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

  • ‘-’ : New setting for users are loaded i.e. .bashrc
  • “without-hyphen”: Keeps using my existing environment, no .bashrc is loaded

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.

https://wiki.archlinux.org/index.php/Su

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).

Reference



Let me know if you have any questions or comments.
It will help me to improve/learn.


< Older   Further Reading   Newer >