What's the difference between "sudo su -" and "sudo -i"? [duplicate]
Possible Duplicate:
What is the difference between sudo -i and sudo su -
I know both commands result in gaining a root-shell. But there are some differences. On some servers e.g. the prompt is different:
nomike@testerver:~> sudo -i
root@testerver:~> logout
nomike@testerver:~> sudo su -
[root@testerver ~]#
So I guess the handling of ".bashrc" ".bash_profile" and ".profile" is somehow different.
Does one invoke a login shell and the other not?
Solution 1:
Both sudo -i
and sudo su -
will get you an interactive login shell. The difference you are seeing is because of the way that sudo is configured to handle environment variables and in this case PS1. Your PS1 is different from root's PS1. If you look in /etc/sudoers you will probably find an env_keep
line that contains PS1.
Defaults env_keep += "MAIL PS1 PS2 QTDIR ..."
This instructs sudo to keep (amongst others) the PS1
environment variable in the environment of the commands you are running so this is what you see (different prompts).
When you run sudo su -
the modified environment is passed to su
which then runs a login shell, su doesn't force the environment to be the same so it gets set up with whatever is in root's initialisation files.