Restore OS password
Introduction
Prerequisites:
- The disk is not encrypted
- The bios is not protected by password or it is resettable by removing CMOS battery
- You can reach recovery mode
Note:
Having a complete hardware access to a machine, VM, etc usually means full control of a system.
Take steps to protect digital security by going the opposite direction.
They are not bullet-proof but each measure makes it more difficult for unauthorized access.
Of course it also makes it more difficult to restore your system so take actions proportional to risks.
Ubuntu
- Boot in recovery mode (shift / esc / del / F1-F12 to visit boot menu)
- Drop to root shell
mount -o rw,remount /- Check the username by
ls /home passwd usernameexit
Centos 7
- In boot menu, move to the usual kernel you boot from
- Press e on the kernel to enter edit mode
- Append rd.break to the line starting with linux16. It should look like “linux16 … rd.break” afterwards
- Ctrl-X to save and exit
- It reboots, choose the kernel to boot from
mount -o remount,rw /sysroot/chroot /sysrootpasswdload policy -ichcon -t shadow_t /etc/shadow