RedHat/Centos修改root密码

        Linux主机忘记密码,只要你能接触物理主机都可以修改root密码的!

  Redhat6.x 5.x  / Centos6.x  5.x

01、开机-空格/enter

02、e-编辑模式

CentOS 6.4和RHEL6.X 单用户模式找回密码,启动的时候,提示“输入任何键进入菜单(英文好像是: press any key to enter menu)”,这时回车或空格

出现:    “CentOS (2.6.32-358.e16.i686)”  菜单。
下面有提示:输入'e' to edit the commands before booting.

因此,我们输入 'e'字符,接着的界面会有3个选项出现:
    root (hd0,0)
    kernel /vmlinuz-...
    initrd /initramfs...

 我们选择中“kernel ...”这一行,然后按下"e"键,这时提示:
    <BOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

后面追加 空格+single 等价 1
在这行的末尾输入 " single" (注意,single前面有个空格),回车,
这将回到3个选项的那个界面(这时第二项依旧处于选中状态),然后按下 'b',以此选项启动Linux

然后等待,操作系统启动完成,期间不需要输入密码!命令行显示为:
[root@]#
现在我们可以以root身份执行命令了。

passwd

修改密码:

(a) 对于CentOS 6.4 我们可以用"passwd"命令修改密码!
(b) 对于RHEL 6.x,"passwd"命令无效!
我们执行命令:
echo 'ybxiang123' | passwd --stdin root
密码就改成了'ybxiang123'

然后用 "init 6" 重启! / reboot


Redhat7.x  / Centos7.x

1. 重启redhat7,上下 e(编辑)
e ----------> linux16    末尾添加
物理机: rd.break
虚拟机: rd.break console=tty0

ctrl + x  继续

switch_root:/# mount -o rw,remount /sysroot
switch_root:/# chroot /sysroot
sh-4.2# passwd root
sh-4.2# touch /.autorelabel    //SELinux开启的情况下
sh-4.2# exit
switch_root:/# reboot

参考文档:

http://www.linuxidc.com/Linux/2014-09/106446.htm

原文地址:https://www.cnblogs.com/xiaochina/p/5699251.html