Thursday, 7 March 2019

linux - What's the difference between sudo su - and sudo -i?


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.



Answer



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.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...