bash 中不同“类型”的 root 访问权限有何区别?

bash 中不同“类型”的 root 访问权限有何区别?

什么是区别之间:

sudo su -

su -i

哪一个更优于另一个?

   -, -l, --login
          Start the shell as a login shell with an environment similar to a real login:

             o      clears all the environment variables except TERM and variables specified by --whitelist-environment

             o      initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH

             o      changes to the target user's home directory

             o      sets argv[0] of the shell to '-' in order to make the shell a login shell

   su - run a command with substitute user and group ID

摘录自该man su页面。

答案1

-i该命令没有参数su,因此区别在于一个有效而另一个无效。

如果您的意思是su -l,它在 Ubuntu 机器上仍然默认不起作用,因为帐户root已被锁定并且没有密码可以输入。

-和参数之间没有区别-l。它们都是同一选项的变体。实际上,您man在问题中包含了页面中告诉我们这一点的一行。

您在帖子中包含的摘录中解释了使用--l或参数(它们都是一样的)和不使用参数之间的区别。这部分说明了它在没有参数的情况下会做什么:--login

For  backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOG‐
NAME if the target user is not root).  It is recommended to always use the --login option (instead of its shortcut -) to avoid  side  effects  caused  by
mixing environments.

请注意,这su不仅仅代表root。它并不代表超级用户就像注释一样sudo。它代表替代用户并且您可以指定要使用的用户作为参数,以该用户身份运行命令

相关内容