Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by Shane Madden, Khaled, faker, chutz, Iain Jan 17 '13 at 13:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.