# Root Password Recovery [TOC] - 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](https://zh.wikipedia.org/wiki/GNU_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. ![](https://i.imgur.com/akRdHTP.png) 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** ![](https://i.imgur.com/z8hlaSk.png) 2. The `mount -a` mentioned in article[2] doesn't work, should use the following one instead: ```bash= mount -o rw -u / ``` - :x: ![](https://i.imgur.com/dluuQOT.png) - :heavy_check_mark: ![](https://i.imgur.com/pQqoz1m.png) ### CentOS SOP - The way to change boot mode at GRUB is different between CentOS7 and previous version. 1. Press `e` at default boot option ![](https://i.imgur.com/duj2x5p.png) 2. It will enter a text editor ![](https://i.imgur.com/szXHIrr.png) 3. Add ` rd.break` at the end of the line which starts with `Linux` or `kernel` ![](https://i.imgur.com/cOZjvgf.png) > 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 ```bash= mount -o remount,rw /sysroot/ chroot /sysroot ``` 6. Change password ![](https://i.imgur.com/ihPu9XT.png) 7. Reboot ![](https://i.imgur.com/3WqFDJo.png) - Two ways - Faster ```bash= load_policy -i chcon -t shadow_t /etc/shadow exit ``` - Slower ```bash= touch /.autorelabel exit ``` ## Reference ### Official ### Article 1. [How to Reset or Change the Root Password in Ubuntu/CentOS](https://phoenixnap.com/kb/how-to-change-root-password-linux) 2. [如何重設 Ubuntu、CentOS、Debian、FreeBSD 的 root 密碼](https://blog.miniasp.com/post/2012/06/12/How-to-reset-root-password-for-Ubuntu-CentOS-Debian-FreeBSD) 3. [Recover – Reset Forgotten Linux Root Password](https://linuxconfig.org/recover-reset-forgotten-linux-root-password) 4. [CentOS 7 如何重置root密碼](https://autumncher.pixnet.net/blog/post/462809249-%E3%80%90centos7%E3%80%91%E5%A6%82%E4%BD%95%E9%87%8D%E7%BD%AEroot%E5%AF%86%E7%A2%BC-%28how-to-recover-root-pas)