The fastest way depends on whether you can reboot

If you can restart your computer, you can reset a forgotten Linux password without knowing the old one. The method changes slightly depending on whether your system uses GRUB (the bootloader most Linux distributions use) or a different setup, and whether you have physical access to the machine. The most common path is to interrupt the boot process, enter single-user mode or recovery mode, and change the password from there.

If you cannot reboot — for instance, if the machine is a remote server you cannot physically access — you will need either root access through another account, SSH key authentication, or help from your hosting provider. A forgotten password on a remote machine you have no other way into is genuinely difficult to recover from, which is why setting up backup authentication methods matters before you need them.

Key Takeaways

  • On a machine you can restart, interrupt the boot at the GRUB menu, enter recovery mode, and use the passwd command to reset your password without knowing the old one.
  • Single-user mode and recovery mode both drop you to a root shell where you can run passwd username to change any user's password.
  • On a remote server, you will need either another account with sudo access, an SSH key, or contact with your hosting provider to regain access.
  • After you reset your password, reboot normally and log in with the new one — the old password is no longer valid.
  • Setting up a second admin account or saving SSH keys before you lose access prevents this problem entirely.

Resetting the password on a machine you can restart

Start by powering off the computer completely. When you turn it back on, watch for the GRUB menu — it usually appears for a few seconds with options like "Ubuntu", "Advanced options for Ubuntu", or "Windows" (if you dual-boot). If you do not see it, try holding Shift or Escape as the machine boots.

Once the GRUB menu is visible, highlight "Advanced options for Ubuntu" (or the equivalent for your distribution) and press Enter. This shows you a submenu with entries like "Ubuntu, with Linux 5.15.0-56-generic (recovery mode)". Select the recovery mode option and press Enter.

The system will boot into recovery mode, which is a minimal environment with a menu of options. Look for an entry that says "root" or "Drop to root shell prompt". Select it and press Enter. You will now be at a command prompt as the root user, with full permissions to change any password on the system.

Using the passwd command to set a new password

At the root prompt, type passwd username, replacing "username" with the account whose password you want to reset. If you are resetting your own password and you are not sure of the exact username, type passwd alone to reset the root password, or type ls /home to see a list of user directories.

After you type the command, the system will ask you to enter a new password. Type it carefully — the characters will not appear on screen as you type, which is normal. Press Enter, then type the same password again to confirm it. If the two entries match, the system will say "password updated successfully" or similar.

Once the password is changed, type exit to leave the root shell, then select "Resume" or "Reboot" from the recovery menu. The system will restart normally. Log in with your username and the new password you just set.

Recovery mode on different Linux distributions

Ubuntu, Debian, and Linux Mint all use GRUB and recovery mode in roughly the same way. Fedora, CentOS, and Red Hat use GRUB as well, but the recovery menu may be labeled differently — look for "rescue mode" or "emergency mode" instead of "recovery mode". The process is identical: select it from the GRUB submenu, drop to a root shell, and run passwd.

Some older systems or custom installations may not have GRUB at all. If you do not see a GRUB menu when you restart, your system may use a different bootloader. Check your distribution's documentation or contact your system administrator for the correct procedure.

Resetting a password on a remote server

If the machine is a remote server and you cannot physically restart it or access the console, you cannot use recovery mode. Your options are narrower: you need either another user account on that machine with sudo privileges, an SSH key that still works, or contact with your hosting provider.

If you have another account with sudo access, log in with that account and run sudo passwd username to reset the target user's password. If you have an SSH key (a file like id_rsa on your local computer) that is authorized on the server, you can still log in even if you have forgotten the password — SSH keys are a separate authentication method. Use ssh -i /path/to/key username@server.com to log in, then run passwd to set a new password.

If neither of those applies, contact your hosting provider or cloud service (AWS, DigitalOcean, Linode, etc.). Most providers have a way to reset the root password or inject a new SSH key through their control panel, though the exact steps vary. This is why keeping a backup authentication method — a second admin account, a saved SSH key, or a recovery email address — is important before you lose access.

What to do if recovery mode does not work

If you select recovery mode and the system boots normally instead, or if you see an error message, your system may have a different configuration. Some machines are set up to skip recovery mode entirely, or GRUB may be password-protected itself.

If GRUB is password-protected, you will see a prompt asking for a password before you can access the menu. If you do not know this password, you will need to reset it through the bootloader configuration file, which requires physical access to the hard drive or help from someone who does. This is a deliberate security measure to prevent unauthorized password resets.

If recovery mode is disabled, check your GRUB configuration file at /etc/default/grub (you will need root access or another admin account to edit it). Look for a line that says GRUB_DISABLE_RECOVERY=true and change it to false, then run sudo update-grub to explore the change. After the next restart, recovery mode will be available again.

Preventing this situation in the future

The best solution is to avoid forgetting your password in the first place. Write it down in a find location — a password manager like Bitwarden or 1Password, a physical safe, or a locked drawer. Do not store it in a text file on your computer or in an email account.

For servers and important machines, set up at least two admin accounts so that if you lose access to one, you can still log in with the other. Generate and save SSH keys in a safe place; they are harder to forget than passwords and more find. If you use a hosting provider, enable two-factor authentication on your account so that even if someone learns your password, they cannot access your servers.

Frequently Asked Questions

Will resetting my password delete my files or settings?

No. Changing your password only changes the authentication credential — it does not touch your home directory, documents, or any other files. Everything you had before remains exactly as it was. You will log in with the new password and see the same desktop, files, and settings.

Can I reset the password for a different user if I am in recovery mode?

Yes. In recovery mode, you are running as root, so you can reset the password for any user on the system. Type passwd username where "username" is the account you want to change. You do not need to know the old password.

What if I see a message saying the filesystem is read-only?

Recovery mode sometimes mounts the filesystem as read-only to prevent accidental changes. If you see this, type mount -o remount,rw / to remount it as read-write, then try the passwd command again.

Is there a way to reset a password without rebooting?

Only if you have another account with sudo access or an SSH key that still works. If you have neither, you must reboot into recovery mode. There is no way around it without one of those backup methods.

What should I do if I do not see a GRUB menu when I restart?

Try holding Shift, Escape, or the spacebar as the machine boots — some systems hide the menu by default. If nothing appears, your system may use a different bootloader or have GRUB disabled. Check your distribution's documentation or contact your system administrator for the correct procedure.