When you cannot log into your Linux machine, the simplest fix involves editing the boot parameters to drop into a root shell. This guide will walk you through exactly how to reset password on linux using several proven methods, from single-user mode to live USB recovery.
Forgetting your password happens to the best of us. Whether you are a system administrator or a home user, being locked out of your own computer is frustrating. The good news is that Linux offers multiple ways to regain access without reinstalling the entire system.
Below you will find a complete, step-by-step breakdown of every major technique. Each method is tested on popular distributions like Ubuntu, CentOS, Fedora, and Debian.
How To Reset Password On Linux
This section covers the most reliable and commonly used approach: editing GRUB boot parameters. It works on almost every Linux distribution that uses GRUB as its bootloader.
Method 1: Reset Password Using GRUB Recovery Mode
GRUB is the bootloader for most Linux systems. By interrupting the normal boot process, you can gain root access without entering a password.
- Reboot your computer. As soon as the BIOS screen disappears, press and hold the Shift key (for UEFI systems, press Esc repeatedly). This brings up the GRUB menu.
- Select the kernel entry you normally boot into. It is usually the first option.
- Press e to edit the boot parameters. You will see a screen with a lot of text.
- Find the line that starts with linux or linux16. It often contains parameters like
ro quiet splash. - Navigate to the end of that line. Add a space and then type:
init=/bin/bashorrd.break(for RHEL/CentOS 7+). - If you used
init=/bin/bash, press Ctrl+X or F10 to boot. The system will drop you into a root shell. - If you used
rd.break, you will need to remount the filesystem as read-write first. Type:mount -o remount,rw /sysrootthenchroot /sysroot. - Now you are at a root prompt. Type
passwd yourusername(replaceyourusernamewith your actual username). - Enter your new password twice. Make sure it is strong but memorable.
- If you used
init=/bin/bash, you must remount the root filesystem as read-write first. Type:mount -o remount,rw /before changing the password. - After changing the password, type
exec /sbin/initto continue booting normally, or typereboot -fto restart.
This method works on Ubuntu, Debian, Linux Mint, and most Debian-based distributions. For Fedora and CentOS, the rd.break variant is more reliable.
Method 2: Reset Password Using Single User Mode
Single user mode is another boot-time trick. It loads only essential services and gives you a root shell without authentication.
- Reboot and access the GRUB menu as described above.
- Press e on your chosen kernel entry.
- Find the line starting with linux or linux16.
- At the end of that line, replace
ro quiet splashwithrw init=/bin/bash. - Press Ctrl+X to boot. You will land in a root shell immediately.
- Type
passwd yourusernameand follow the prompts. - Type
exec /sbin/initto resume normal boot.
Single user mode is slightly simpler than the GRUB recovery method because you do not need to remount the filesystem manually. However, it may not work on all distributions, especially those with strict SELinux policies.
Method 3: Reset Password Using A Live USB
If you cannot access the GRUB menu at all, a live USB is your best bet. This method requires a second computer to create the bootable media.
- Download a Linux live ISO (Ubuntu, Fedora, or any distribution) and create a bootable USB using tools like Rufus or Etcher.
- Boot your locked machine from the USB drive. You may need to change the boot order in BIOS.
- Select “Try Ubuntu” or “Live Environment” (do not install).
- Open a terminal. Identify your hard drive partition using
lsblkorfdisk -l. Look for the partition with your Linux installation (usually/dev/sda1,/dev/nvme0n1p2, etc.). - Mount that partition to
/mnt:sudo mount /dev/sda1 /mnt(replace with your actual partition). - If you have a separate boot partition, mount it as well:
sudo mount /dev/sda2 /mnt/boot. - Chroot into your installed system:
sudo chroot /mnt. - Now you are inside your installed system as root. Type
passwd yourusername. - Enter the new password twice. Exit the chroot by typing
exit. - Unmount the partitions:
sudo umount /mnt/boot /mnt(if applicable) thensudo umount /mnt. - Reboot and remove the USB drive. Log in with your new password.
This method is universal and works on any Linux distribution. It also gives you a chance to backup important files if needed.
Method 4: Reset Password Using Recovery Mode (Ubuntu Specific)
Ubuntu and its derivatives have a built-in recovery mode that simplifies the process.
- Reboot and hold Shift to enter GRUB.
- Select “Advanced options for Ubuntu” then choose the kernel with “(recovery mode)” at the end.
- From the recovery menu, select “root – Drop to root shell prompt.”
- The filesystem will be mounted as read-only. Remount it as read-write:
mount -o remount,rw /. - Type
passwd yourusernameand set a new password. - Type
exitto return to the recovery menu, then select “resume” to boot normally.
Recovery mode is the most user-friendly option for Ubuntu users. It requires no manual editing of boot parameters.
Method 5: Reset Password Using Systemd Rescue Target
Modern distributions using systemd can boot into a rescue target that provides a root shell.
- Access the GRUB menu and press e on your kernel entry.
- Find the line starting with linux. At the end, add:
systemd.unit=rescue.target. - Press Ctrl+X to boot. You will be prompted for the root password. If you do not know it, this method will not work.
- Alternatively, add
systemd.unit=emergency.targetfor an even more minimal environment. - Once in the rescue shell, type
passwd yourusername.
This method is less common but useful if you have physical access and know the root password. It is not ideal for forgotten passwords.
Important Considerations Before Resetting
Resetting a password through boot methods bypasses normal security. This is why physical access to the machine is critical. If your system uses full disk encryption (LUKS), you will need the encryption passphrase first. Without it, none of these methods work.
Also, if SELinux is enforcing, you may need to relabel the filesystem after the reset. On CentOS or Fedora, run touch /.autorelabel before rebooting. This ensures file contexts are correct.
For systems with secure boot enabled, some distributions may block the modified boot parameters. In that case, disable secure boot in BIOS temporarily, reset the password, then re-enable it.
Common Pitfalls And Troubleshooting
Here are a few issues you might encounter and how to fix them:
- Keyboard not working in GRUB: Try a different USB port or use a PS/2 keyboard. Some UEFI systems have issues with USB keyboards during boot.
- Filesystem is read-only: Always remount with
mount -o remount,rw /before changing passwords. Otherwise, the change will fail silently. - Password change succeeds but login fails: You may have typed the password incorrectly. Use the
passwdcommand again and ensure caps lock is off. - Account is locked or expired: Use
passwd -u yourusernameto unlock the account, then set a new password. - Root password vs user password: If you are resetting the root password, use
passwdwithout a username. For a user account, specify the username.
Preventing Future Lockouts
Once you regain access, consider setting up a password recovery method. You can create a secondary user with sudo privileges, or set up SSH keys for remote access. Another option is to write down your password and store it in a safe place.
For system administrators, using a centralized authentication system like LDAP or Active Directory can eliminate local password issues. Regular backups of critical files also reduce the impact of a lockout.
Frequently Asked Questions
Q: Can I reset a password without physical access?
A: No. All methods require physical access to the machine or remote console access via IPMI or iDRAC. Without it, you cannot interrupt the boot process.
Q: Will resetting the password delete my files?
A: No. Resetting the password only changes the authentication credentials. All your files, settings, and applications remain intact.
Q: What if I have full disk encryption?
A: You must enter the LUKS passphrase first. If you forgot that too, you will lose all data. There is no backdoor for encrypted drives.
Q: Can I reset a password on a cloud server?
A: Yes, but you need to use the cloud provider’s recovery console or mount the disk to another instance. Most providers offer a “reset password” option in their dashboard.
Q: Is it possible to reset a password using a live USB on a Mac with Linux?
A: Yes, but you may need to disable SIP (System Integrity Protection) first. The process is similar to the live USB method described above.
Q: How do I reset a password on Linux without GRUB?
A: If your system uses a different bootloader like LILO or U-Boot, you will need to consult the specific documentation. Most modern systems use GRUB.
Final Thoughts
Knowing how to reset password on linux is an essential skill for anyone using the operating system. The methods outlined here are reliable, well-tested, and work across different distributions. Always try the GRUB recovery method first, as it is the fastest. If that fails, move to the live USB approach.
Remember to keep your system updated and maintain a backup of important data. Password recovery is a safety net, but preventing lockouts is always better. With these steps, you can confidently regain access to your Linux machine in minutes.