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

白昼怎懂夜的黑 提交于 2019-12-03 16:58:56

问题


Both commands:

sudo -i -u username
sudo su - username

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


回答1:


The su command stands for "substitute user", and allows you to become different user(super user). sudo su changes 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 sudoers file.

With sudo -i you 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 .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.



来源:https://stackoverflow.com/questions/31696324/whats-the-difference-between-sudo-i-u-user-and-sudo-su-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!