Try   HackMD

Root Password Recovery

  • One simple way is to let super-user uses privilege to change root's password.
  • But if the super-user account cannot be accessed or there is no super-user, here is another way to fix the problem GRUB.

GRUB

  • Restart the system and hold the Shift key or press the Esc key to enter into safe mode (recovery mode). Once you have entered safe mode, you will see the GRUB menu.

Ubuntu SOP

  1. Press Esc will enter BIOS, so you should press shift in order to see the option of recovery mode.
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. Get into root shell prompt without password, then you can change root's password.

FreeBSD SOP

  1. Press shift then press shift-2 enter Boot Single user
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. The mount -a mentioned in article[2] doesn't work, should use the following one instead:
    ​mount -o rw -u /
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

CentOS SOP

  • The way to change boot mode at GRUB is different between CentOS7 and previous version.
  1. Press e at default boot option
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. It will enter a text editor
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. Add rd.break at the end of the line which starts with Linux or kernel
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    If the version of CentOS is lower than 7, the added string will be single

  4. Press Ctrl-x to enter single-user mode
  5. Remount the /sysroot/ and change root directory to /sysroot by following commands
    ​mount -o remount,rw /sysroot/ ​chroot /sysroot
  6. Change password
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  7. Reboot
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    • Two ways
      • Faster
        ​​​load_policy -i ​​​chcon -t shadow_t /etc/shadow ​​​exit
      • Slower
        ​​​touch /.autorelabel ​​​exit

Reference

Official

Article

  1. How to Reset or Change the Root Password in Ubuntu/CentOS
  2. 如何重設 Ubuntu、CentOS、Debian、FreeBSD 的 root 密碼
  3. Recover – Reset Forgotten Linux Root Password
  4. CentOS 7 如何重置root密碼