CentOS 6.X

image-20220904210448292

如上按【Esc】键进入内核界面:

image-20220904203447567

按a进入如下界面:

image-20220904205619095

按【空格】键,输入“1” 或者输入single、S、s,再【回车】都可以进入单用户模式

image-20220904205813631

image-20220904205842987

在单用户模式下修改密码

echo testpwd | passwd --stdin root

image-20220904210303700

重启os验证密码

reboot

CentOS 7.X

方法1

在启动grub菜单,选择编辑选项启动

image-20220904210901571

按e进入编辑模式

image-20220904211217553

找到linux16这一行,将ro改为 rw init=/sysroot/bin/sh

image-20220904211713087

现在按下 Ctrl+X ,进入单用户模式

image-20220904211913772

#修改root根
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#重置密码
echo testpwd | passwd --stdin root
#更新selinux上下文
touch /.autorelabel
#退出chroot
exit
#重启验证
reboot

方法2

在启动grub菜单,选择编辑选项启动

image-20220904210901571

按e进入编辑模式

image-20220904211217553

找到linux16这一行,尾部添加内核参数rd.break

image-20220904222041080

现在按下 Ctrl+X ,进入单用户模式

image-20220904211913772

#以读写权限重新挂载/sysroot
mount -o remount,rw /sysroot
#修改根为/sysroot
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#修改密码
echo testpwd2 | passwd --stdin root
#更新SELinux安全上下文
touch /.autorelabel
#退出/sysroot
exit
#重启验证密码
reboot

备注:如果操作系统没有开SELinux,则不需要做touch /.autorelabel这一步骤

CentOS 8.X

image-20220904212745498

image-20220904212854129

在以linux起首quiet结尾的这行的行尾处输入【空格】+ rd.break,

image-20220904213830004

然后键盘按【ctrl+X】进入紧急救援模式

image-20220904213933009

执行mount -o remount,rw /sysroot,以读写权限重新挂载/sysroot

image-20220904214125041

执行chroot /sysroot/切换其目录下

image-20220904214243627

中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。

LANG=en

重置密码
echo testpwd | passwd --stdin root

image-20220904214507879

系统selinux开启的情况下,需要执行touch /.autorelabel,更新SELinux上下文

image-20220904214712470

exit退出sysroot

重启reboot验证密码

Oracle Linux 6.X

image-20220904220059667

按a进入如下界面:

image-20220904220204913

按【空格】键,输入“1” 或者输入single、S、s,再【回车】都可以进入单用户模式

image-20220904220318599

在单用户模式下修改密码

echo testpwd | passwd --stdin root

image-20220904220428053

重启os验证密码:reboot

Oracle Linux 7.X

方法1

image-20220904220856543

按e进入编辑模式

image-20220904221043677

找到linux16这一行,将ro改为 rw init=/sysroot/bin/sh

image-20220904221145717

现在按下 Ctrl+X ,进入单用户模式

image-20220904221230876

#修改root根
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#重置密码
echo testpwd | passwd --stdin root
#更新selinux上下文
touch /.autorelabel
#退出chroot
exit
#重启验证
reboot

方法2

image-20220904220856543

按e进入编辑模式

image-20220904221043677

找到linux16这一行,尾部添加内核参数rd.break

image-20220904222041080

按Ctrl+X启动进入单用户模式

image-20220904222128406

#以读写权限重新挂载/sysroot
mount -o remount,rw /sysroot
#修改根为/sysroot
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#修改密码
echo testpwd2 | passwd --stdin root
#更新SELinux安全上下文
touch /.autorelabel
#退出/sysroot
exit
#重启验证密码
reboot

image-20220904222325911

RHEL 6.X

image-20220904222714342

按a进入如下界面:

image-20220904222954197

image-20220904222744389

按【空格】键,输入“1” 或者输入single、S、s,再【回车】都可以进入单用户模式

image-20220904223102163

在单用户模式下修改密码

echo testpwd | passwd --stdin root

image-20220904223146067

重启os验证密码

reboot

RHEL 7.X

方法1

image-20220904223341499

按e进入编辑模式

image-20220904221043677

找到linux16这一行,将ro改为 rw init=/sysroot/bin/sh

image-20220904221145717

现在按下 Ctrl+X ,进入单用户模式

image-20220904221230876

#修改root根
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#重置密码
echo testpwd | passwd --stdin root
#更新selinux上下文
touch /.autorelabel
#退出chroot
exit
#重启验证
reboot

方法2

image-20220904223341499

按e进入编辑模式

image-20220904221043677

找到linux16这一行,尾部添加内核参数rd.break

image-20220904222041080

按Ctrl+X启动进入单用户模式

image-20220904222128406

#以读写权限重新挂载/sysroot
mount -o remount,rw /sysroot
#修改根为/sysroot
chroot /sysroot
#中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#修改密码
echo testpwd2 | passwd --stdin root
#更新SELinux安全上下文
touch /.autorelabel
#退出/sysroot
exit
#重启验证密码
reboot

image-20220904222325911

RHEL 8.X

image-20220904224815947

在以linux起首quiet结尾的这行的行尾处输入【空格】+ rd.break,

image-20220904224951163

然后键盘按【ctrl+X】进入紧急救援模式

image-20220904213933009

执行mount -o remount,rw /sysroot,以读写权限重新挂载/sysroot

mount -o remount,rw /sysroot

image-20220904214125041

执行chroot /sysroot/切换其目录下

image-20220904214243627

中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。

LANG=en

重置密码

echo testpwd | passwd --stdin root

image-20220904214507879

系统selinux开启的情况下,需要执行touch /.autorelabel,更新SELinux上下文

image-20220904214712470

exit退出sysroot

重启reboot验证密码

总结

针对Linux6:

#1、按【ESC】进入GRUB界面
#2、按 a 进入修改内核参数界面
#3、在尾部按【空格】键,再输入“1” 或者输入single、S、s,
#4、再按【回车】进入单用户模式
#5、单用户模式下修改root密码
echo testpwd | passwd --stdin root
#6、重启OS验证密码

针对Linux7:

方法1:

#1、grub菜单,按 e 进入编辑模式
#2、找到linux16这一行,将ro改为 rw init=/sysroot/bin/sh
ro  -->   rw init=/sysroot/bin/sh
#3、按下 Ctrl+X ,进入单用户模式
#4、修改root根
chroot /sysroot
#5、中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#6、重置root密码
echo testpwd | passwd --stdin root
#7、更新selinux上下文
touch /.autorelabel
#8、退出chroot
exit
#9、重启验证
reboot

方法2:

#1、grub菜单,按 e 进入编辑模式
#2、找到linux16这一行,尾部添加内核参数rd.break
rd.break
#3、按下 Ctrl+X ,进入单用户模式
#4、以读写权限重新挂载/sysroot
mount -o remount,rw /sysroot
#5、修改根为/sysroot
chroot /sysroot
#6、中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#7、修改root密码
echo testpwd2 | passwd --stdin root
#8、更新SELinux安全上下文
touch /.autorelabel
#9、退出/sysroot
exit
#10重启验证密码
reboot

针对Linux8:

#1、grub菜单,按 e 进入编辑模式
#2、找到linux16这一行,尾部添加内核参数rd.break
rd.break
#3、按下 Ctrl+X ,进入单用户模式
#4、以读写权限重新挂载/sysroot
mount -o remount,rw /sysroot
#5、修改根为/sysroot
chroot /sysroot
#6、中文语言安装系统需要执行LANG=en,否则passwd的提示显示为乱码的方块。
LANG=en
#7、修改root密码
echo testpwd2 | passwd --stdin root
#8、更新SELinux安全上下文
touch /.autorelabel
#9、退出/sysroot
exit
#10重启验证密码
reboot
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐