sudo -s or sudo -i
sudo allows users to run programs with the security privileges of another user (superuser or other users). Of the supported options, what’s difference between -s
and -i
?
Both options run an interactive shell if no command is specified:
|
|
The difference is that when using -i
:
sudo attempts to change to that user’s home directory before running the shell. The command is run with an environment similar to the one a user would receive at log in. -
man sudo
Let’s assume the current directory is at /
:
|
|
Changing directory is not attempted when using -s
option.
sudo is commonly used to elevate the privilege to execute as the superuser, and usually done in place rather than in the superuser’s home directory, such as:
|
|
Therefore, when running as superuser, use -s
:
|
|
When running as another user, use -i
:
|
|