This question already has an answer here:
- su vs sudo -s vs sudo -i vs sudo bash 3 answers
I was wondering what the difference is between sudo -i and sudo su?
|
This question already has an answer here:
I was wondering what the difference is between |
|||||
marked as duplicate by Gilles, Renan, jasonwryan, Chris Down, Anthon Nov 3 '13 at 7:05This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
|||||
|
|||||
|
Based on the descriptions from the man pages for
excerpt sudo man page
ExampleI have a user account,
In the above output, the 1st column is my real UID (uid) and the 2nd is my effective UID (euid). Becoming root via (su)
Now I'm root, but I still maintain my environment and my real UID is still
However my environment is still
Becoming root via (su -) or (sudo -i)
With an
However my environment is now
So then what's the difference?Well let's try the above with
Now let's look at the same info:
Well one major thing is my effective ID and real ID are both 0 (
Comparing environmentsIf we count the number of lines in say the 3 methods, perhaps there is some additional info to be had.
We are left with these 3 files:
Already we can see that something is up with just a plain Number of lines in each:
There's really no need to look further at the They're virtually identical except for a few cosmetic variables, such as sudo
su -
As you can see Take aways?
What about
|
|
|||
|
|
@ChrisDown - I've ditched
who from the example, it wasn't helping me anyway, I'm going straight to /proc to show what I want.
– slm♦
Nov 2 '13 at 10:27
|
||
|
|
|||
|
|
|||
|
both
sudo and su go through the PAM stack. If it logs under one, it should be logging under the other. Also sudo su will strip the environment just like sudo -i will. In fact I don't see you mention sudo su anywhere in your answer...
– Patrick
Nov 2 '13 at 17:42
|
|
I think @slm misread the question, so providing another answer. He did hit on the main point, about one being a login shell and the other not. When chaining I personally consider There are basically 5 common ways of invoking a root shell via sudo
Note, that these rules only apply when using them to gain a shell. There is a difference between |
|||||
|
|
The second one preserves the current directory (pwd) but the first command drops the user to the root's home directory. |
|||
|
|