Document Scope
This article provides step-by-step instructions to change the root password if you have forgotten it or are having trouble with it. By following these steps, you should be able to successfully change the root password on your Linux system.
Prerequisites
This guide assumes the following:
- You have already created a bootable USB containing a live Linux distribution (such as Ubuntu or Fedora). If you haven't please see the KB article Prepare a Bootable USB.
- The drive containing the boot partition you want to change the password for is physically installed.
- You can access the BIOS boot menu to boot from the live USB
Step 1: Create a Directory for Mounting the Target Drive
First, open a terminal window on the live distribution. Once opened, Create a directory to mount the target drive containing the boot partition:
-
root@live:~$ mkdir /home/exx/target
Step 2: Locate the Boot Partition of the Target Drive
Identify the boot partition of the target drive using the fdisk -l command (in this example, it would be '/dev/sdb1'):
root@live:~$ fdisk -l
Disk /dev/sda: 32.1 GB, 32094814208 bytes, 62685184 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a0fa4
Device Boot Start End Blocks Id System
/dev/sda1 * 32 62685183 31342576 c W95 FAT32 (LBA)
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0007fbf1
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1026047 512000 83 Linux
/dev/sdb2 1026048 1953523711 976248832 8e Linux LVM
Step 3: Mount the Target Drive Partition
Mount the target drive partition to the directory you just created:
root@live:~$ mount /dev/sdb1 /home/exx/target
Step 4: Change Root to the Mounted File System
Use the chroot command to change root to the mounted file system:
root@live:~$ chroot /home/exx/target
Step 5: Change the Root Password
Use the passwd command to change the root password:
root@live:~$ passwd
Changing password for user root.
New password:
Step 6: Exit the chroot Shell
Exit the chroot shell by typing:
root@live:~$ exit
Step 7: Safely Unmount the Drive
Unmount the drive from the filesystem you created:
root@live:~$ umount /dev/sdb1 /home/exx/target
Comments
0 comments
Please sign in to leave a comment.