How to reset Ubuntu server password using live cd in bare metal or hypervisor?

How to reset ubuntu server password using live cd in bare metal or hypervisor?

Losing or forgetting admin credentials can be a serious issue, especially for critical systems. Without access to admin credentials, it can be difficult to perform essential tasks such as system maintenance, security updates, and troubleshooting. Similar thing happened to me when I completely forgot my postgreSQL database password and the data was extremely important. Following process helped me out:

Incase of bare metal installation, boot the server using live CD and select Ubuntu Server installation.

1

Incase of hypervisor installation, add the live CD image in VM setting and boot.

2

During boot process of VM, press ESC to enter boot menu.

3

Under boot menu, select CD-ROM Drive to boot from live CD.

4

Following processes are same for both bare metal or hypervisor OS installation. Select Install Ubuntu and let the system load the Ubuntu installation screen.

5

The Help option will be available in all screens. Choose help option through keyboard and enter shell.

6

You will enter the shell with root prompt. Enter command “sudo fdisk -l | more” to list all disks in the system.

7

Identify your root “/” disk from the fdisk output and mount on system.

8

List all the current mounts in the system using command “df -h”. Don’t care about “/cow” mount which is mounted on “/”. The /cow mount stands for Copy-on-Write, which is used in the live installation system to provide a writable layer over the read-only filesystem (usually compressed and mounted as part of the live image).

9

You have to correctly identify “/” mount from fdisk list. In my case, my “/” mount was installed on /dev/sda4. Mount the disk using command “sudo mount /dev/sda4 /mnt”.

10

The “sudo chroot /mnt” command is used to change the root directory to /mnt. Use “passwd ” command to change the concerned administrator user password.

11

Now exit from chroot session, unmount the “/” disk mounted on “/mnt” and reboot.

12

Login with the newly set credentials.

13

Thank You