zoukankan      html  css  js  c++  java
  • The difference between su and su-


    Time:2018/3/12

    Author:xibeiyelang

    Title:The difference between su and su-


    1.su : run a command with substitute user and group ID.

    2.su - : run a command with substitute user and group ID and change username path.

    Example:

    eg1.su - root is the same as su - just like login as root,
    then the shell is login shell,which mean it will expericene a login process,
    usually .bash_profile and .bashrc will be sourced.

    eg2.su root is the same as su like you open an interactive shell in root name,
    then only .bashrc will be sourced.


    说明:

    su命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shell环境仍然是普通用户的Shell;而后者连用户和Shell环境一起切换成root身份了。只有切换了Shell环境才不会出现PATH环境变量错误。su切换成root用户以后,pwd一下,发现工作目录仍然是普通用户的工作目录;而用su -命令切换以后,工作目录变成root的工作目录了。用echo $PATH命令看一下su和su -以后的环境变量有何不同。以此类推,要从当前用户切换到其它用户也一样,应该使用su -命令。

    语法:

    $ su [user_name]
    su 命令可以用来交互地更改你的用户ID和组ID。 Su是switch user 或set user id的一个缩写。这个命令让你开启一个子进程,成为新的用户 ID 和赋予你存取与这个用户ID 关联所有文件的存取权限。因此,出于安全的考虑,你在实际转换身份时,会被要求输入这个用户帐号的密码。
    如果没有参数,su 命令将你转换为 root(系统管理员)。root 帐号有时也被称为超级用户,因为这个用户可以存取系统中的任何文件。也正是这个原因,许多人将su命令看成是 supper-user(超级用户)的一个缩写。当然,你必须要提供 root密码。 想要回到你原先的用户身份,不要再使用 su 命令,你只需要使用 exit命令退出你使用su命令而生成的新的对话进程。
    $ su – username
    一些配置文件是为你的对话线索而设立的。当你使用命令 su username时,你的对话特征和你原始的登录身份一样。如果你想要你的对话进程拥有转换后的用户 ID一致的特征,你要使用短斜杠: su – username。

    小结:

    1)超级用户root切换到普通用户无需密码
    2)普通用户切换到root账号需要root密码
    3)普通用户之间切换需要对应的账号密码


    参考:https://www.cnblogs.com/Nice-Boy/p/6137955.html

  • 相关阅读:
    C# 不用添加WebService引用,调用WebService方法
    贪心 & 动态规划
    trie树 讲解 (转载)
    poj 2151 Check the difficulty of problems (检查问题的难度)
    poj 2513 Colored Sticks 彩色棒
    poj1442 Black Box 栈和优先队列
    啦啦啦
    poj 1265 Area(pick定理)
    poj 2418 Hardwood Species (trie树)
    poj 1836 Alignment 排队
  • 原文地址:https://www.cnblogs.com/xbyl/p/8547151.html
Copyright © 2011-2022 走看看