How to change the root password if it is forgotten

When the root password is forgotten, a new password can be created by booting Linux into the single user mode first. To boot into the single user mode, uses the following steps:

System using Grub boot loader

  1. When prompted, press any key to enter the grub menu after starting up the system
  2. Press 'e' to edit the commands before booting
  3. Move cursor key to the kernel line (2nd line)
  4. Press 'e' to edit the selected commands in the boot sequence
  5. Append the word 'single' to the end of the command. For example:
        grub edit> kernel /vmlinuz-2.6.12-11_FC3aslsmp ro root=LABEL=/ single
    
  6. Press enter key
  7. Press 'b' to boot

When the shell prompt is available, run 'passwd' and enter a new root password. Afterward, run 'reboot' to restart the system.

System using LILO boot loader

At the LILO menu, press Ctrl-X to acess the command prompt. Next enter 'linux single' and press Enter key to boot into the single user mode. When the shell prompt is available, run 'passwd' and enter a new root password. Afterward, run 'reboot' to restart the system.