4

I see that su - makes the shell a login shell from su --help. I'm curious what the differences are between this and a normal su command.

I know there seems to be a difference in the paths, any other differences or is that pretty much the only difference?

4 Answers4

5

difference i usually meet is difference in environment variables. su - change environment, su don't. For example: "su -" can give different PATH, accessing other tools, Can give other HOME with different configuration ( ~/.ssh !/.Xauthority etc)

4

AFAIK su - simulates a fresh login, so triggers everything related to logging in, while su simply switches the user to root.

MMM
  • 182
  • 4
2

A login shell sources ~/.profile if it exists. Therefore, it really depends, what do you have in your ~/.profile?

Usually these are environment variable differences, such as the PATH, or the prompt (PS1 environment variable) but obviously there can be other differences.. It really depends on what you put in your shell config scripts.

Rich Homolka
  • 32,350
0

from man su

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

so the next question is what is a login shell, and how it differs from a non-login shell.

In man bash under INVOCATION you can read a long and pedantic section, that boils down to something like: login shell runs the profile file(s) (e.g. /etc/profile and ~/.bash_profile) while the interactive non-login shell runs the bashrc files.

Chen Levy
  • 1,685