На этот вопрос уже есть ответ здесь:
Я новый пользователь Ubuntu, и некоторые люди говорят мне использовать sudo -i
для получения root, а другие говорят мне использовать sudo -s
. В чем разница? Какой из них использовать и когда?
Основное различие между sudo -i
и sudo -s
заключается в следующем:
sudo -i
дает вам корневую среду, т. Е. Ваш ~/.bashrc
игнорируется. sudo -s
предоставляет вам среду пользователя, поэтому ваш ~/.bashrc
уважается. Вот пример, вы можете видеть, что у меня есть приложение lsl
в моем каталоге ~/.bin/
, которое доступно через sudo -s
, но недоступно с sudo -i
. Также обратите внимание, что подсказка Bash меняется как будет с sudo -i
, но не с sudo -s
:
dotancohen@melancholy:~$ ls .bin
lsl
dotancohen@melancholy:~$ which lsl
/home/dotancohen/.bin/lsl
dotancohen@melancholy:~$ sudo -i
root@melancholy:~# which lsl
root@melancholy:~# exit
logout
dotancohen@melancholy:~$ sudo -s
Sourced .bashrc
dotancohen@melancholy:~$ which lsl
/home/dotancohen/.bin/lsl
dotancohen@melancholy:~$ exit
exit
Хотя sudo -s
удобна для предоставления вам среды, с которой вы знакомы, I Рекомендуется использовать sudo -i
по двум причинам:
.bashrc
. sudo -i
-i [command] The -i (simulate initial login) option runs the shell speci‐ fied by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's -c option. If no command is specified, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. The security policy shall initialize the environment to a minimal set of variables, similar to what is present when a user logs in. The Command Environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use.
sudo -s
-s [command] The -s (shell) option runs the shell specified by the SHELL environment variable if it is set or the shell as specified in the password database. If a command is specified, it is passed to the shell for execution via the shell's -c option. If no command is specified, an interactive shell is executed.