Scott

linux系统下如何切换到root用户 2 years ago

linux
1453个字符
共有77人围观

linux系统下切换到root用户有多种方法,具体如下所示:

1、sudo命令

$ sudo

执行命令后,输入当前管理员用户的密码就可以短暂得到超级用户的权限了。

2、sudo -i命令

$ sudo -i

通过此命令直接输入当前管理员用户的密码就可以进入root用户了。

3、如果我们想一直使用root权限,可以使用su命令

首先执行如下命令重新设置root用户的密码。

$ sudo passwd root

然后就可以自由地切换到root用户了。

执行命令:

$ su

接着输入root用户的密码即可切换到root用户了。

如果我们想回到普通用户权限,直接执行命令su xxx或者是exit即可。

root@local:~# su --help

Usage:
 su [options] [-] [<user> [<argument>...]]

Change the effective user ID and group ID to that of <user>.
A mere - implies -l.  If <user> is not given, root is assumed.

Options:
 -m, -p, --preserve-environment      do not reset environment variables
 -w, --whitelist-environment <list>  don't reset specified variables

 -g, --group <group>             specify the primary group
 -G, --supp-group <group>        specify a supplemental group

 -, -l, --login                  make the shell a login shell
 -c, --command <command>         pass a single command to the shell with -c
 --session-command <command>     pass a single command to the shell with -c
                                   and do not create a new session
 -f, --fast                      pass -f to the shell (for csh or tcsh)
 -s, --shell <shell>             run <shell> if /etc/shells allows it
 -P, --pty                       create a new pseudo-terminal

 -h, --help                      display this help
 -V, --version                   display version