Hackerparagraph,IT-Security, Linux (Image © DALL-E)
Accessing the GRUB Bootloader
The first step in the recovery process requires access to the Grand Unified Bootloader (GRUB) menu. By default, the menu is not visible during a normal boot process. To access the GRUB menu, the system must be powered on or restarted while holding down the Shift key or repeatedly pressing the ESC key. In environments using VirtualBox, the Shift key is the preferred method for accessing the boot menu.
Changing the Kernel Boot Parameters
Once the GRUB menu is active, the administrator must use the arrow keys to navigate to the Ubuntu entry and press the e key. This opens the boot parameter editor, where the kernel instructions can be modified.
Locate the line beginning with the word linux. Within this line, the section ro quiet splash $vt_handoff is important. To enable administrative changes, replace this string with the following:
rw init=/bin/bash
The rw prefix is crucial because it instructs the system to mount the root filesystem with read and write permissions, while init=/bin/bash instructs the system to start a Bash shell instead of the default init process. After making the change, reboot the system by pressing Ctrl + X or F10.
Checking File System Permissions
After the reboot, the system enters a root shell environment. Before attempting to change the password, you must verify that the file system has been mounted with the correct permissions. You can confirm this by running the following command:
mount | grep -w /
The output must display the rw flag, confirming that the root directory is writable.
Performing the Password Reset
If the file system is in read/write mode, the password for the root account is changed using the passwd utility:
passwd
The system prompts you to enter a *new password and then to confirm it. After successful entry, the system displays a message indicating that the password has been updated.
To ensure system integrity and security, the root filesystem should be set back to read-only mode before exiting the shell:
mount -o remount,ro /
The final step is to return the system to its normal operating state. This is done by rebooting the system or by starting the init process with one of the following commands:
exec /sbin/init
OR
reboot
After a successful reboot, the new root credentials can be used to log in as the administrator.
Questions and Answers About Resetting the Root Password
Why is the “rw” parameter necessary during the boot process?
By default, Ubuntu boots with the root filesystem in read-only (ro) mode to prevent accidental changes during the boot sequence. Since the password file is stored on the hard drive, the filesystem must be explicitly set to read/write (rw) access so that the passwd command can overwrite the existing hash with the new password.
What is the function of “init=/bin/bash” in the GRUB editor?
The init process is the first process started by the kernel and is responsible for launching all other processes, including the login manager. By replacing the default init with /bin/bash, the kernel skips the usual authentication and service startup sequence and places the user directly into a root shell with maximum privileges.
Does this procedure differ when using a virtual machine such as VirtualBox?
The basic technical steps are identical; however, the timing and the key required to access the GRUB menu may vary. In VirtualBox, the Shift key is usually the most reliable method for interrupting the boot process and accessing the GRUB menu.
Why is it necessary to remount the file system as read-only before rebooting?
Remounting the file system as read-only using mount -o remount,ro / ensures that all changes are properly written to the hard drive and that the system is restored to a safe state. This prevents potential file system corruption that could occur if the system is forced to reboot while the root directory is still in a writable state.
Can this method be used to reset a standard user password?
Yes. Once access to the root shell has been gained using the methods described above, the administrator can reset any user password on the system by appending the username to the “passwd” command (e.g., passwd username).
