Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
xiaomacai
V2EX  ›  Linux

Linux 问题请教

  •  
  •   xiaomacai · Jun 29, 2017 · 2969 views
    This topic created in 3420 days ago, the information mentioned may be changed or developed.

    sudo su - username 跟 sudo su username 有什么不同的地方,之前使用后一种进入用户后会存在部分环境变量未加载的情况,原因是什么?

    5 replies  •  2017-06-29 14:23:18 +08:00
    Beavan
    Beavan
    Jun 29, 2017
    1
    没有- 虽然切换了用户,但一些环境变量还是用的切换用户的环境变量,不属于完整切换。
    加上- 完整切换,对应的环境变量也切换为对应用户身边。
    besto
    besto
    Jun 29, 2017
    2
    man su:

    -, -l, --login
    Provide an environment similar to what the user would expect had the user logged in directly.

    When - is used, it must be specified before any username. For portability it is recommended to use it as last option,
    before any username. The other forms (-l and --login) do not have this restriction.
    xiaomacai
    xiaomacai
    OP
    Jun 29, 2017
    3
    @besto 恩恩,貌似不同 linux 版本里面说明是不太一样的
    zent00
    zent00
    Jun 29, 2017
    4
    一句话简单概括,login shell 和 non-login shell 的差异,前者会切换用户身份并加载目标用户的环境变量,后者只是切换身份到目标用户。
    GGGG430
    GGGG430
    Jun 29, 2017
    5
    google: suid,sgid
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4734 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:57 · PVG 10:57 · LAX 18:57 · JFK 21:57
    ♥ Do have faith in what you're doing.