V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
xiaomacai
V2EX  ›  Linux

Linux 问题请教

  •  
  •   xiaomacai · 2017-06-29 11:08:22 +08:00 · 1863 次点击
    这是一个创建于 2464 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    5 条回复    2017-06-29 14:23:18 +08:00
    Beavan
        1
    Beavan  
       2017-06-29 11:14:14 +08:00
    没有- 虽然切换了用户,但一些环境变量还是用的切换用户的环境变量,不属于完整切换。
    加上- 完整切换,对应的环境变量也切换为对应用户身边。
    besto
        2
    besto  
       2017-06-29 11:19:59 +08:00
    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
       2017-06-29 11:28:48 +08:00
    @besto 恩恩,貌似不同 linux 版本里面说明是不太一样的
    zent00
        4
    zent00  
       2017-06-29 11:50:58 +08:00
    一句话简单概括,login shell 和 non-login shell 的差异,前者会切换用户身份并加载目标用户的环境变量,后者只是切换身份到目标用户。
    GGGG430
        5
    GGGG430  
       2017-06-29 14:23:18 +08:00
    google: suid,sgid
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3578 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:10 · PVG 08:10 · LAX 17:10 · JFK 20:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.