「CentOS」- 重置 ROOT 密码

问题描述

未做文档,交接疏忽……总之会出现各种需要重置密码的场景…………本文将介绍如何重置ROOT密码。

该笔记将记录:在 Linux 中,如何重置密码,以及相关问题的解决办法。

解决方案

本文只进行简单记录,不深入操作细节。

Ubuntu 20.04 LTS

How to Reset Forgotten Root Password in Ubuntu
grub2 – How to get to the GRUB menu at boot-time? – Ask Ubuntu

1)当进入 GURB 菜单时,按 [e] 编辑启动项;
2)编辑 linux /boot/… 行尾,类似 ro quiet splash 内容;
3)修改为 rw init=/bin/bash 并 [F10] 以继续启动;
4)进入系统,passwd,修改密码;
5)最后,exec /sbin/init,启动系统;

Q:某些系统,/etc/default/grub: GRUB_HIDDEN_TIMEOUT=0,导致无法显示 GRUB 菜单
A:当开机时:基于 BIOS 系统,按 [Shift] 键;基于 UEFI 系统,按 [Esc] 键;

CentOS 7

How To Reset Root Password On CentOS 7

GRUB => 编辑对应启动菜单项 => 找到 linux16 行 => 将 ro 替换为 rw init=/sysroot/bin/sh 配置 => 启动,进入单用户模式

chroot /sysroot

passwd root

touch /.autorelabel (如果系统加载SELinux模块)

exit

reboot