6

在 Fedora 36 中如何重置 root 密码-51CTO.COM

 2 years ago
source link: https://os.51cto.com/article/709956.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在 Fedora 36 中如何重置 root 密码-51CTO.COM

在 Fedora 36 中如何重置 root 密码
作者:Sk 2022-05-26 10:30:48
你是否忘记了 Fedora 中的 root 密码?或者你想更改 Fedora 系统中的 root 用户密码?没问题!本文将指导你在 Fedora 操作系统中完成更改或重置 root 密码的步骤。

在 Fedora 中重置忘记的 root 密码。

你是否忘记了 Fedora 中的 root 密码?或者你想更改 Fedora 系统中的 root 用户密码?没问题!本手册将指导你在 Fedora 操作系统中完成更改或重置 root 密码的步骤。

注意: 本手册已在 Fedora 36 和 35 版本上进行了正式测试。下面提供的步骤与在 Fedora Silverblue 和旧 Fedora 版本中重置 root 密码的步骤相同。

步骤 1 - 打开 Fedora 系统并按下 ESC 键,直到看到 GRUB 启动菜单。出现 GRUB 菜单后,选择要引导的内核并按下 e 编辑选定的引导条目。

b82f9a9851d80fa957b326c4e399587005115f.png

Grub Menu In Fedora 36

步骤 2 - 在下一个页面中,你将看到所有启动参数。找到名为 ro 的参数。

426eef0757a030202b34392952eb777fb784a9.png

Find ro Kernel Parameter In Grub Entry

步骤 3 - 将 ro 参数替换为 rw init=/sysroot/bin/sh。请注意 rw 和 init=/sysroot...之间的空格。修改后的内核参数行应如下所示。

051664c02484c350d3e328f250d4e107f79f2d.png

Modify Kernel Parameters

步骤 4 - 上述步骤更改参数后,按 Ctrl+x 进入紧急模式,即单用户模式。

在紧急模式下,输入以下命令以 读/写 模式挂载根文件系统(/)。

chroot /sysroot/
7383f150065eaba9510562cc3a216a96fc091b.png

Mount Root Filesystem In Read, Write Mode In Fedora Linux

步骤 5 - 现在使用 passwd 命令重置 root 密码:

passwd root

输入两次 root 密码。我建议使用强密码。

54daf9c998d48cde27785801f8262f34246419.png

Reset Or Change Root Password In Fedora

步骤 6 - 重置 root 密码后,运行以下命令在重启时启用 SELinux 重新标记:

touch /.autorelabel
99ac88b8585bc67f858336f01bba86694293d2.png

Enable SELinux Relabeling On Reboot In Fedora

步骤 7 - 最后,退出单用户模式并通过运行以下命令将 Fedora 系统重启到正常模式:

exit
reboot

等待 SELinux 重新标记完成。这将需要几分钟,具体时长取决于文件系统的大小和硬盘的速度。

b63025767ca035ad66745640386df82303edfa.png

SELinux Filesystem Relabeling In Progress

步骤 8 - 文件系统重新标记完成后,你可以使用新的 root 密码登录到你的 Fedora 系统。

53fc6eb741c3f022da7511aa9d4cc358e0b36c.png

Login To Fedora As Root User

如你所见,在 Fedora 36 中重置 root 密码的步骤非常简单,并且与 在 RHEL 中重置 root 密码 及其衍生版本(如 CentOS、AlmaLinux 和 Rocky Linux)完全相同。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK