Support >
  About cybersecurity >
  If you've forgotten your Ubuntu password, you can reset the root password like this
If you've forgotten your Ubuntu password, you can reset the root password like this
Time : 2026-01-20 12:09:29
Edit : Jtti

When faced with the Ubuntu login screen, you enter your password but receive an incorrect message, and you can't remember the correct password. Forgetting your password is a common and tricky problem, whether you haven't used the machine in a long time or inherited someone else's old equipment. Fortunately, on Ubuntu, even if you forget all user passwords (including root), as long as you have physical access to the machine or console access to the server, there's a way to reset them. This process doesn't rely on memory, but rather on intervention in the Linux boot process.

You need to reboot the target Ubuntu system. At the beginning of boot, when you see the GRUB boot menu (usually displaying the Ubuntu logo and several options), quickly press the `Esc` key or the `Shift` key (or a long press `Shift` on some UEFI systems) to enter the menu selection interface. If you miss this brief window, the system will boot directly, and you'll need to reboot again. In the GRUB menu, you'll see "Ubuntu" as the default boot option, along with other advanced options.

Use the arrow keys to select the "Ubuntu" line (usually the first highlighted item), but don't press Enter immediately. At this point, press `e` to edit the boot parameters on this line. You will enter a text editor containing the kernel boot configuration information. You need to find the line that starts with `linux`, which usually ends with parameters like `ro quiet splash $vt_handoff`. The key is to change `ro` (read-only) to `rw init=/bin/`. `rw` indicates mounting the root filesystem in read-write mode, while `init=/bin/` tells the kernel not to run the default initialization system after boot, but to directly start a shell. This bypasses the normal login authentication process.

After finding the correct line and modifying it, press `Ctrl + X` or `F10` to start the system using these edited parameters. After a few seconds, you will enter a shell running as `root`, and your current working directory is the root directory of the root filesystem. Note that you now have the highest privileges, but all system services (including network) have not yet been started, and the environment is very basic. Now you can directly operate on the core system files.

The first step is to remount the root filesystem as read-write. Although `rw` is specified in the boot parameters, it's best to explicitly execute this once to be on the safe side. This is because in some cases, the filesystem might still be mounted as read-only.

mount -o remount,rw /

Next, use the `passwd` command to change the password. If you want to reset the password for the `root` user (many Ubuntu desktop versions disable root by default, but you can set a password for it), simply run `passwd`. The system will prompt you to enter a new password and confirm it. Nothing will be displayed on the screen while you type (not even an asterisk), which is normal security behavior.

passwd

More commonly, you need to change the password for a regular user, such as your own account username `alex`. In this case, you need to specify the username.

passwd alex

Similarly, enter the new password twice as prompted. If you see "password updated successfully" or a similar message, the password has been changed successfully. In rare cases, if the system uses external authentication such as LDAP, the above method may not be applicable, but it is effective for standard local user accounts.

Important Warning: Before proceeding to the next step, a critical operation must be completed. Since we booted abnormally, the system may attempt a filesystem check (fsck) upon reboot. To avoid potential filesystem errors, we need to perform a synchronization operation and ensure the filesystem state is clean.

sync

After completing the password reset and synchronization, you need to reboot the system. Simply type `reboot -f` in this shell. The `-f` parameter indicates a forced reboot.

reboot -f

The system will reboot normally. When you reach the login screen again, you can log in using the new password you just set.

The above describes the standard method under traditional BIOS and GRUB boot. If your system uses UEFI Secure Boot, the process may be slightly different. You may need to select "Ubuntu Advanced Options" when the GRUB menu appears, and then press `e` to edit the kernel in recovery mode. The principle is the same: modify the boot parameters to obtain a root shell.

For cloud servers or virtual machines, if you cannot access the GRUB menu (e.g., via VNC or a console provided by your cloud provider), you may need to use Rescue Mode or a recovery image. Most cloud platforms offer this functionality. You need to mount a temporary rescue system from the console to boot, then mount the original system's root partition to the rescue environment, use the `chroot` command to switch the root directory to the original system, and finally execute the `passwd` command in the original system's environment.

# Example of operation in the rescue environment (the specific partition device name needs to be adjusted according to the actual situation)

mkdir /mnt/rescue

mount /dev/sda1 /mnt/rescue # Assuming the original system's root partition is /dev/sda1

chroot /mnt/rescue

passwd username

exit

reboot

Resetting the password essentially involves interrupting the normal boot process to gain root privileges. This also reminds us that physical access permissions are crucial in Linux security. If someone else can access your machine and perform the above operations, they can reset the password and access all data. Therefore, for machines storing sensitive data, full-disk encryption (such as LUKS) should be considered. This way, even if the password is reset, the data cannot be accessed without the encryption key.

The entire process is not complicated, but it requires careful operation, especially when modifying startup parameters; avoid changing other parts. After successful completion, it is recommended to log in immediately and check if the system status is normal. It's also best to take this opportunity to properly record the new password in a secure password manager to avoid falling into the same predicament again.

Pre-sales consultation
JTTI-Defl
JTTI-Ellis
JTTI-Jean
JTTI-Selina
JTTI-Coco
JTTI-Amano
JTTI-Eom
Technical Support
JTTI-Noc
Title
Email Address
Type
Sales Issues
Sales Issues
System Problems
After-sales problems
Complaints and Suggestions
Marketing Cooperation
Information
Code
Submit