4

It is my understanding that they do the same: they ask for my password (if I am allowed in /etc/sudoers), and give me a login shell as root.

Is there any difference between them?

sudo su -
sudo -i

Also, what's the difference between

sudo su
sudo -s

I think that they both ask for my password, and give me a shell with my old environment variables.

1

1 Answer 1

4

There is little difference in the command pairs you are wondering about.

The first pair attempts to simulate a fresh login as the new user-- there could be some difference in the environmental variables supplied, as sudo su - is going to try and preserve existing environmental variables, while sudo -i will set very specific environmental variables and strip all others (check your man pages for specifics).

For the second pair, the difference in behavior is this: sudo su will always start the shell listed in the user's /etc/passwd, whereas sudo -s will check the SHELL environmental variable first, and only execute the shell in /etc/passwd if SHELL is unset.

2
  • Note that the set of variables preserved by "su -"/"sudo su -" is also very restricted, maybe similar to what sudo -i does. Jul 23, 2011 at 17:55
  • sudo su - is going to try and preserve existing environmental variables ? I read that su - makes the shell a login shell & changes the environmental variables to those of the new user source
    – A.D.
    May 24, 2013 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .