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

Linux 问题请教

  •  
  •   xiaomacai · Jun 29, 2017 · 2692 views
    This topic created in 3265 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
        1
    Beavan  
       Jun 29, 2017
    没有- 虽然切换了用户,但一些环境变量还是用的切换用户的环境变量,不属于完整切换。
    加上- 完整切换,对应的环境变量也切换为对应用户身边。
    besto
        2
    besto  
       Jun 29, 2017
    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
        3
    xiaomacai  
    OP
       Jun 29, 2017
    @besto 恩恩,貌似不同 linux 版本里面说明是不太一样的
    zent00
        4
    zent00  
       Jun 29, 2017
    一句话简单概括,login shell 和 non-login shell 的差异,前者会切换用户身份并加载目标用户的环境变量,后者只是切换身份到目标用户。
    GGGG430
        5
    GGGG430  
       Jun 29, 2017
    google: suid,sgid
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2901 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:13 · PVG 17:13 · LAX 02:13 · JFK 05:13
    ♥ Do have faith in what you're doing.