Table of Contents
Reset Root Password
On CentOS & RHEL
1. Reboot and Access GRUB Menu
- Reboot the system.
- During boot, when GRUB appears, press e to edit the default kernel entry.
2. Edit the Kernel Boot Parameters
- Find the line beginning with linux16
- Replace:
ro
- with:
rw init=/sysroot/bin/sh
3. Boot with Modified Parameters
- Press Ctrl + X to boot into single-user mode.
4. Access the System
- Once booted, you'll be at a prompt. Run:
chroot /sysroot
5. Reset Password
- Enter:
passwd root
- Set the new password.
6. Relabel SELinux Contexts (if enabled)
- If SELinux is enforcing, run:
touch /.autorelabel
7. Exit and Reboot
- Run:
exit reboot
On Ubuntu
1. Reboot and Access GRUB Menu
- Reboot the system.
- When GRUB menu appears, select the entry you want to modify and press e.
2. Edit the Boot Parameters
- Look for the line that starts with:
linux
- Replace:
ro quiet splash
- or similar with:
rw init=/bin/bash
3. Boot into Shell
- Press Ctrl + X or F10 to boot.
4. Reset Password
- At the root shell prompt (#), enter:
passwd root
- Enter a new password when asked.
5. Remount and Reboot Cleanly
- Ensure the root filesystem is mounted correctly:
mount -o remount,rw /
- Then reboot:
exec /sbin/init
- or
reboot -f
