bash `sudo -i -u user` 和 `sudo su - user` 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31696324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:22:23  来源:igfitidea点击:

What's the difference between `sudo -i -u user` and `sudo su - user`?

bashsudosu

提问by Jan Dudulski

Both commands:

两个命令:

sudo -i -u username
sudo su - username

Will log me in as usernameif I enter my password. Is there actually any difference between these commands?

将我登录,就像username我输入密码一样。这些命令之间实际上有什么区别吗?

回答by sTg

The sucommand stands for "substitute user", and allows you to become different user(super user). sudo suchanges the current user to root but environment settings (PATH)would remain same. It allows user who have permissions to execute a command as the superuser or another user, as specified in the sudoersfile.

su命令代表“替代用户”,并允许您成为不同的用户(超级用户)。 sudo su将当前用户更改为 root 但environment settings (PATH)将保持不变。它允许有权限的用户以超级用户或其他用户的身份执行命令,如sudoers文件中所指定。

With sudo -iyou get a clean root shell. The ?i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profileor .loginwill 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 -i干净的根外壳。?i(模拟初始登录)选项运行由目标用户的密码数据库条目指定的 shell 作为登录 shell。这意味着shell 将读取特定于登录的资源文件,例如.profile.login。如果指定了命令,它将通过 shell 的 ?c 选项传递给 shell 以执行。如果未指定命令,则执行交互式 shell。