The fastest way to change root password depends on whether you know the current one

If you are logged in as root or can run commands with sudo, you can change the root password in seconds using the passwd command. If you have forgotten the root password entirely, you will need to restart your machine and access the bootloader or single-user mode — a longer process that requires physical access to the computer.

The method you use depends on your situation: whether you remember the password, whether you have sudo access, and what Linux distribution you are running. Most home users and server administrators will use one of the first two methods below.

Key Takeaways

  • If you are logged in as root, type passwd at the command line, then enter the new password twice.
  • If you have sudo access but are not logged in as root, type sudo passwd root to change the root password without knowing the old one.
  • If you have forgotten the root password and cannot use sudo, you must restart the machine and boot into single-user mode or the GRUB bootloader.
  • Linux does not show your password as you type it — this is normal and a security feature.
  • After changing the root password, test it when ready by logging out and logging back in as root.

Changing root password when you are logged in as root

Open a terminal and type the command exactly as shown:

passwd

The system will prompt you to enter the current root password. Type it and press Enter. You will not see the characters appear on screen — this is intentional and keeps your password safe from shoulder surfers. Then the system will ask you to enter a new password. Type it carefully, press Enter, and type it again to confirm. If the two entries match, the password changes when ready.

If you make a typo and the two passwords do not match, the system will tell you and ask you to try again. There is no penalty for getting it wrong — you can attempt as many times as you need.

Changing root password when you have sudo access

If you are logged in as a regular user but have sudo permissions, you can change the root password without knowing the current one. Open a terminal and type:

sudo passwd root

The system will ask for your own password (not the root password), because sudo requires you to prove you are an authorized user. Enter your password and press Enter. Then follow the same process as above: enter the new root password, press Enter, type it again to confirm, and press Enter.

This method is common in Ubuntu and other distributions where the root account exists but is not normally used for daily login. If you do not have sudo access, you will see a message saying "user is not in the sudoers file" — in that case, you will need to use the bootloader method described below.

Recovering a forgotten root password using single-user mode

If you have forgotten the root password and do not have sudo access, you must restart the machine and interrupt the normal boot process. The steps differ slightly between distributions, but the principle is the same: you boot into a mode where you have root access without needing a password.

Restart your computer. As soon as it starts to boot, hold down the Shift key (on most systems) or the Escape key (on some older systems) to enter the GRUB bootloader menu. You should see a list of kernel versions and options. Highlight the top entry and press 'e' to edit it.

Find the line that starts with linux or linux16. Go to the end of that line and add the word single (with a space before it). Then press Ctrl+X to boot. The system will start in single-user mode and drop you to a root prompt without asking for a password.

At the root prompt, type passwd and follow the steps above to set a new password. When you are done, type exit to return to the normal boot process, or type reboot to restart the machine cleanly.

Recovering a forgotten root password using the GRUB bootloader (older systems)

On some older Linux systems, the bootloader menu does not appear automatically. Restart the machine and hold down Shift or Escape repeatedly as it boots. If a menu appears, follow the single-user mode steps above.

If no menu appears and you see only a blank screen or a loading bar, your system may have GRUB password protection enabled, or the bootloader may be configured differently. In that case, you will need to boot from a live USB or DVD — a separate Linux system on removable media that lets you access the hard drive without logging in. Create a live USB using a tool like Balena Etcher or Rufus on another computer, boot from it, and use the file manager to navigate to the root user's home directory on your main drive.

Testing your new password when ready

After you change the root password, do not close the terminal yet. Open a second terminal window or tab and try to log in as root using the new password. Type su - or su root, then enter the new password when prompted. If you can log in, the change worked. If you cannot, you still have the original terminal open and can try again.

This test takes 30 seconds and saves you from being locked out of your own system. If something went wrong — a typo, a misremembered password, or a system issue — you will know when ready while you still have a way to fix it.

Why root password changes sometimes fail

The most common reason a password change appears to fail is that the two passwords you entered do not match. The system will tell you this explicitly, and you can try again. Another reason is that your terminal is not actually connected to the root account — for example, if you typed sudo passwd instead of sudo passwd root, you may have changed your own password by mistake.

On some systems, the root account is disabled entirely, and you cannot log in as root even with the correct password. This is common in Ubuntu. In that case, you can still use sudo to run commands as root, and you do not need to change the root password. If you need to log in as root directly, you will need to enable the root account first — a separate process that involves setting a password and then enabling login.

Frequently Asked Questions

What if I type the password wrong and lock myself out?

You cannot lock yourself out by typing a password wrong during the passwd command. The system will straightforward tell you the passwords do not match and ask you to try again. You can attempt as many times as you need. The only way to be truly locked out is to forget the password and lose access to sudo and single-user mode at the same time.

Can I change the root password from a regular user account?

Only if you have sudo access. Type sudo passwd root and enter your own password when prompted. If you do not have sudo access, you cannot change the root password without restarting the machine and using single-user mode.

Is it safe to use the root account for daily login?

Most Linux distributions discourage logging in as root for daily work. Using sudo for individual commands is safer because it creates a record of what was run and by whom, and it limits the damage if a script or program goes wrong. However, changing the root password is still important for security and recovery purposes.

Why does my password not show up when I type it?

Linux hides passwords as you type them — no asterisks, no dots, nothing. This is a security feature that prevents someone from seeing how long your password is or how many characters you have typed. Keep typing normally and press Enter when you are done.

What should I do if single-user mode asks for a password?

Some systems are configured to require a password even in single-user mode. If this happens, you will need to boot from a live USB or DVD instead. Create the live USB on another computer using the same Linux distribution, boot from it, and access your hard drive through the file manager to reset the password manually.