Noé*_*ieu 8 linux su sudo environment-variables
我想知道这样做之间是否有任何区别(在环境中?)
sudo su - user
Run Code Online (Sandbox Code Playgroud)
和
sudo -iu user
Run Code Online (Sandbox Code Playgroud)
据我所知:通过使用 sudo su - user 我以用户身份打开一个新 shell,破折号提供用户的环境变量(而 sudo su 用户没有)并使用 sudo -iu 用户(-u 用于精确用户,- i 用于“模拟初始登录”)。
那么,有什么区别吗?
除了第一个需要用户能够以root身份执行su,第二个需要以用户身份执行bash
谢谢 !
这是 sudo 手册页上关于“-i”选项的内容
-i The -i (simulate initial login) option runs the shell specified in
the passwd(5) entry of the user that the command is being run as.
The command name argument given to the shell begins with a `-' to
tell the shell to run as a login shell. sudo attempts to change to
that user's home directory before running the shell. It also ini-
tializes the environment, leaving TERM unchanged, setting HOME,
SHELL, USER, LOGNAME, and PATH, and unsetting all other environment
variables. Note that because the shell to use is determined before
the sudoers file is parsed, a runas_default setting in sudoers will
specify the user to run the shell as but will not affect which
shell is actually run.
Run Code Online (Sandbox Code Playgroud)
这基本上是在告诉我您只是在模拟引用用户的外壳,但有些事情可能与直接登录的预期用户不完全相同。如果你问“什么”这个问题,我无法分辨出我的头顶。但是,如果您使用sudo su - user命令,则不会有任何问题,因为您正在使用所引用用户的设置启动一个新的 shell 进程。在某些情况下,这两个命令可能会导致相同的环境,但在其他一些情况下,我认为会遇到差异。
| 归档时间: |
|
| 查看次数: |
19290 次 |
| 最近记录: |