centos root密码_如何在CentOS中恢复丢失的root密码
centos root密码
In Linux, when you forget your account password, you can easily reset it using a root account. But when you forget your root account password, then you're in a bad situation.
在Linux中,如果您忘记了帐户密码,则可以使用root帐户轻松地将其重置。 但是,如果您忘记了root帐户密码,那么您的处境很糟。
You can’t reset your root account password using a regular user account as a user account can't perform such tasks in general.
您无法使用常规用户帐户重置根帐户密码,因为用户帐户通常无法执行此类任务。
In this article we’ll be covering how to recover your CentOS root password. So let's see how to do it.
在本文中,我们将介绍如何恢复您的CentOS根密码。 因此,让我们来看看如何做。
如何恢复您的root密码-分步操作 (How to recover your root password - step-by-step)
In CentOS, it’s possible to have the scripts that run from the initramfs debug the shell at certain points, provide a root shell, and continue when that shell exists.
在CentOS中,可以使从initramfs运行的脚本在某些时候调试shell,提供根shell,并在该shell存在时继续执行。
While this is mostly meant for debugging, it can also be used to recover a lost root password.
虽然这主要是为了调试,但也可以用来恢复丢失的root密码。
Follow these steps to recover your lost root password.
请按照以下步骤恢复丢失的root密码。
First, reboot the system.
首先,重新启动系统。
Interrupt the boot loader countdown by pressing any key.
通过按任意键中断引导加载程序的倒计时。
Move the cursor to the entry that needs to be booted.
将光标移动到需要引导的条目。
Press “e” to select that entry. After selecting that entry, the below kernel commands will appear.
按“ e”选择该条目。 选择该条目后,将出现以下内核命令。
In the kernel command line, move the cursor to the line that starts with linux16.
在内核命令行中,将光标移动到以linux16开头的行。
Press the “End” key to move the cursor to the end of it. Type “rd.break” (This will break just before control is handed from the initramfs to the actual system).
按“结束”键将光标移到其末尾。 输入“ rd.break”(这将在从initramfs传递控制权之前中断。 到实际系统)。
Then press “Ctrl+x” to save those changes. The Initramfs debug shell will appear.
然后按“ Ctrl + x”保存这些更改。 将显示Initramfs调试外壳。
Next, we have to provide read and write permissions to /sysroot by typing the below command:
接下来,我们必须通过输入以下命令来提供对/ sysroot的读写权限:
mount -o remount,rw /sysroot/
Now switch into chroot jail.
现在切换到chroot*。
chroot /sysroot
In here, /sysroot is treated as the root of the file system tree.
在这里,/ sysroot被视为文件系统树的根。
Next you'll set a new root password.
接下来,您将设置一个新的root密码。
passwd root
And relabel the files.
并重新标记文件。
touch /.autorelabel
Finally, type “exit” twice.
最后,键入两次“退出”。
The first one will exit from the chroot jail.
第一个将从chroot*退出。
The next one will exit from the initramfs debug shell and reboots the system.
下一个将从initramfs调试外壳退出并重新启动系统。
Now you can login as root with your updated password.
现在,您可以使用更新后的密码以root用户身份登录。
Please feel free to let me know if you have any questions. You can contact and connect with me on Twitter.
如有任何疑问,请随时告诉我。 您可以在Twitter上与我联系并建立联系。
Thank you for reading.
感谢您的阅读。
Happy Coding!
编码愉快!
翻译自: https://www.freecodecamp.org/news/how-to-recover-your-lost-root-password-in-centos/
centos root密码
上一篇: JAVA操作HDFS的文件系统
下一篇: GitHub最有毒的仓库