“sudo su”会让我成为 root 用户吗?

“sudo su”会让我成为 root 用户吗?

我已经sudo su在终端中输入了,然后我输入了whoami,终端说我是root用户。那么这是否意味着sudo su我成为了 root 用户,或者我错过了什么?

答案1

是的。答案在man su

SYNOPSIS
   su [options...] [-] [user [args...]]

DESCRIPTION
   su allows to run commands with substitute user and group ID.

   When called without arguments su defaults to running an interactive shell as root.

请注意,建议执行此操作的方法是sudo su -,因为它使用登录 shell 环境启动 root shell:

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

             o      clears all environment variables except for TERM

             o      initializes the environment variables HOME, SHELL, USER, LOGNAME, 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

或者sudo -i按照说明直接运行在这个答案中

相关内容