Skip to content

Lost Root Password?

Losing the root password can be a problem. However, there are two ways to recover the password:

The first is to use a user account that is part of the “Sudoers” group and can change the root password using the sudo command:

$ sudo su - # passwd

If it is not possible to log into the system with a privileged account, it is still possible to restart the computer and enter emergency mode to change the root password.

On Debian/Ubuntu systems, the step by step is:

  1. Restart the computer;
  2. Enter the Grub Menu;
  3. Choose the Menu line that will be used for booting; Press the
  4. E” key to edit the line; Search the editor for
  5. the line that begins with “Linux” or “linux16”;
  6. At the end of this line, give a space, and add the number 1; 9. Press Ctrl-X to restart the system;
  7. Use the passwd command to change the root password;
  8. Restart the system normally;

On systems like CentOS and Fedora, especially those using SELinux, it’s a bit different:

  1. Restart the computer;
  2. Enter the Grub Menu;
  3. Choose the Menu line that will be used for booting; Press the
  4. E” key to edit the line; Search the editor for
  5. the line that begins with “Linux” or “linux16”;
  6. Search for this line by “ro” (readonly). Delete the “ ro” and type instead: “rw init=/sysroot/bin/sh” 11. Press Ctrl-X to restart the system;
  7. Type “chroot /sysroot”;
  8. Use the passwd command to change the root password;
  9. If the system uses SELinux, force it to relabel the root partition with the command ” touch /.autorelabel” 17. Type “exit “;
  10. Restart the system normally with the” reboot “command;