rhel6忘记root密码解决办法

【背景】 测试rhel6下面忘记root密码如何解决

 

【步骤】 系统本来的root密码是123456,我们要改为redhat

1.原来rhel5忘记root密码,直接用光盘户口动到rescue模式下面,运行passwd,完了直接输入reboot就可以了。在rhel6下在不是这样子的。

2.rhel6下面的解决办法

 

A、需要用安装光盘启动,用boot光盘还不行,挂不了p_w_picpath文件,而且rhel6的启动界面也变小了,不像rhel5有一个提示符可以输入命令,像linux rescue 或者是linux text或者是按F5等等  都没有了。只有一个提示 按TAB进入编辑模式。

如图:

 

rhel6丢失root密码_休闲

boot界面

TAB进入编辑状态,如下图:

 

rhel6丢失root密码_休闲_02

boot 编辑模式

按回车,默认也是这样子的,不需要改动,进入急救模式,中间的选择跟原来差不多,下面有一个不太一样的,就是要选择启动bash,以前默认启动的,如下图:

 

rhel6丢失root密码_rhel6_03

shell

OK后进入急救模式,如下图:

 

rhel6丢失root密码_职场_04

passwdroot error

在这里是不能直接修改root密码的,原来的版本是可以直接passwd改root密码的

 

在这里要运行

Source code rhel6丢失root密码_root密码_05 rhel6丢失root密码_rhel6_06 rhel6丢失root密码_职场_07 
chroot /mnt/sysp_w_picpath

如下图:

 

rhel6丢失root密码_休闲_08

chroot

进入chroot环境才可以修改root密码,注意shell的变化,如下图:

 

rhel6丢失root密码_职场_09

passwdroot ok

修改完成后,要重启服务器,在这个chroot环境下也不能直接执行reboot命令,会报错,如下图:

 

rhel6丢失root密码_职场_10

reboot error

要退出chroot环境,执行exit退出,注意shell的变化,如下图:

 

rhel6丢失root密码_休闲_11

exit chroot

然后再执行reboot命令,如下图:

 

rhel6丢失root密码_休闲_12

reboot ok

这样root密码就修改完成了,重启之后就可以用新的root密码登录了。

 

但是在重启的时候出现一个警告,selinux的警告,如下图:

 

rhel6丢失root密码_职场_13

Selinux Warning

官方给出的解释如下:

 

Source code rhel6丢失root密码_root密码_05 rhel6丢失root密码_rhel6_06 rhel6丢失root密码_职场_07 
3.As the Linux root user, run the reboot command to restart the system. During the next boot, file systems are labeled. The label process labels all files with an SELinux context: 
 
*** Warning -- SELinux targeted policy relabel is required.
*** Relabeling could take a very long time, depending on file
*** system size and speed of hard drives.
****
 
Each * character on the bottom line represents 1000 files that have been labeled. In the above example, four * characters represent 4000 files have been labeled. The time it takes to label all files depends upon the number of files on the system, and the speed of the hard disk drives. On modern systems, this process can take as little as 10 minutes.

警告的意思是说,selinux的targeted策略要求重新打标签,应该是对系统所有的文件打上一个selinux标签,速度的快慢由系统文件的多少和硬盘的速度决定。

解决:

setenforce 0