“sudo -H”中的“-H”标志是什么意思?

Aka*_*u M 11 command-line sudo

当我在 Ubuntu 18.04 上安装 Python 3 时,我遇到了命令

sudo -H pip install -U pip
Run Code Online (Sandbox Code Playgroud)

有什么作用-H

pom*_*sky 26

来自man sudo

-H, --set-home
            Request that the security policy set the HOME environment variable 
            to the home directory specified by the target user's password 
            database entry.  Depending on the policy, this may be the default 
            behavior.
Run Code Online (Sandbox Code Playgroud)

因此该-H标志使sudo假设root的主目录HOME而不是当前用户的主目录。否则,用户主目录中的某些文件将归根目录所有,这可能会导致各种问题。

  • 我喜欢这个答案,因为它提到了使用 -H 的原因,这很重要。+1 (4认同)
  • @SergiyKolodyazhnyy https://security.stackexchange.com/a/18399/60135 中介绍了(弱)原因。 (2认同)

归档时间:

查看次数:

5564 次

最近记录:

5 年,9 月 前