Restoring the root user’s password in Linux
Stuff happens in life, and root passwords get lost. So what do you do when you need into the system and the password is gone?
The actual question: how do you restore the root password in Linux?
First, don’t panic — look for a LiveCD of the installed system. If it’s a hosted server, look in the admin panel for a rescue boot or network boot option, or anything else that looks like booting a helper kernel.
Once you’ve booted the system into recovery mode, you need to mount the disk with the files and data.
- List the disks with
fdiskfdisk -lRunning this command may give you the following error:
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.In that case use
gdisk:gdisk -l /dev/sda - Mount the partition into
/mnt(in my case -/dev/sda1. Go by whatgdiskorfdiskshowed you)mount /dev/sda1 /mnt - Switch the system to work with the mounted disk:
chroot /mnt - Reset the password:
passwd