如何设置 root 密码以便我可以使用 su 而不是 sudo?

Zig*_*gnd 37 command-line root password

可能重复:
如何知道我的 root 密码?

我想为 root 定义一个密码,以便我可以su直接使用,而不必在它前面加上sudo. 因为我也想以 root 身份登录。

那么如何为root用户设置密码呢?

Zig*_*gnd 57

警告:直接以root身份登录就像玩火一样,因为一个小小的错误就足以丢失关键数据或使您的系统无法启动。请注意,如果您以root身份登录桌面环境,它们也会无法正常运行

请参阅这些问题以了解为什么sudo首选以及默认情况下禁用 root-login背后的原因:

  1. sudo 相对于 su 有什么好处?
  2. 为什么没有以 root 身份登录的选项?

您可能已经注意到,您无法在 Ubuntu 上以 root 身份登录,这是因为 root 实际上没有设置密码。

输入以下命令:

sudo passwd
Run Code Online (Sandbox Code Playgroud)

系统将提示您输入当前用户的密码,然后是您要为 root 设置的密码。提示的消息应类似于以下内容:

[sudo] password for <username>: <Type your user password and press return>
Type new UNIX password: <Type the root password you want>
Retype new UNIX password: <Retype the root password you chose in the previous prompt>
Run Code Online (Sandbox Code Playgroud)

之后将出现以下消息:

passwd: password updated successfully
Run Code Online (Sandbox Code Playgroud)

如果上述消息出现在您的终端上,您现在可以从当前用户输入以下命令以 root 身份输入:

su
Run Code Online (Sandbox Code Playgroud)

系统将提示您输入您设置的 root 密码。就是这样!


ish*_*ish 11

如果你su在阅读问题中的警告后仍想使用,则无需设置root密码。只需这样做sudo su,您就可以使用常规密码了。


man*_*k13 7

我如何在 ubuntu 上创建根目录:首先我这样做

sudo -i
Run Code Online (Sandbox Code Playgroud)

然后

passwd
Run Code Online (Sandbox Code Playgroud)

正如@Zignd 提到的,经典消息将出现:

Type new UNIX password: [Type the root password you want]
Retype new UNIX password: [Retype the root password you chosen before]
passwd: password updated successfully
Run Code Online (Sandbox Code Playgroud)

然后我可以将其su用作普通根帐户...