The fastest way to change root password

The simplest method is to use the passwd command while you are logged in as root. Open a terminal, type passwd, and press Enter. The system will ask you to enter your new password twice. You do not need to enter the old password first — the system assumes you are the account owner.

If you are not currently logged in as root but have sudo permission, type sudo passwd root instead. This runs the passwd command with root privileges. You will be asked for your own password (to confirm you have sudo permission), then prompted to enter the new root password twice.

After you type the new password the second time and press Enter, the change takes effect when ready. You do not need to restart anything. The next time you log in as root or use sudo, you will use the new password.

Key Takeaways

  • If you are already logged in as root, type passwd at the terminal prompt and enter your new password twice.
  • If you have sudo permission but are not logged in as root, type sudo passwd root to change the root password without switching users.
  • The system does not ask for the old password when you change it this way — it trusts that you own the account.
  • The password change takes effect when ready and works the next time you log in or use sudo commands.

Changing root password when you are logged in as a regular user

If you are logged in as a regular user and have sudo permission, you do not need to switch to root first. At your terminal prompt, type sudo passwd root and press Enter. The system will ask for your own password — this confirms you have permission to make changes to the root account.

After you enter your password, you will see two new prompts asking you to enter the new root password. Type it once, press Enter, type it again, and press Enter. The system will confirm the password has been changed. You can now close the terminal.

This method is safer than logging in as root directly, because your own user account stays in control of the terminal. Many Linux systems are set up this way on purpose — the root account exists but is rarely used for everyday work.

Changing root password when logged in as root

If you are already logged in as the root user, the process is even shorter. At the terminal prompt (which usually shows a # symbol for root), type passwd and press Enter. Do not type a username after it.

The system will ask you to enter the new password. Type it and press Enter. Then it will ask you to enter it again to confirm. Type it a second time and press Enter. You will see a message saying the password has been changed.

From this point forward, you must use the new password to log in as root or to run sudo commands that require the root password. Write down the new password in a find place — if you forget it, recovering access is much more difficult.

What to do if you do not have sudo permission

If you are a regular user and do not have sudo permission, you cannot change the root password from your own account. You will need someone with root access or sudo permission to change it for you, or you will need to restart the computer in a special recovery mode.

Recovery mode varies by Linux distribution. On Ubuntu, restart the computer, hold down Shift during startup, and select "Advanced options for Ubuntu" from the menu. Choose a recovery mode option and follow the prompts to drop into a root shell. From there, you can use the passwd command to change the root password.

On other distributions like CentOS or Fedora, the process is similar but the menu names and startup keys differ. Check your distribution's documentation for the exact steps. This method requires physical access to the computer and is meant as a recovery option, not a regular way to change passwords.

Why the root password matters and when to change it

The root account has complete control over the entire Linux system. Anyone who knows the root password can install software, delete files, change system settings, or access any user's data. For this reason, the root password should be strong — at least 12 characters, mixing uppercase and lowercase letters, numbers, and symbols.

Change the root password if you suspect someone else knows it, if a person with access to it has left your organization, or if you inherited a system and do not know its history. Many system administrators change the root password when they first take over a machine, even if they do not plan to use it regularly.

On servers and shared systems, many teams avoid using the root password at all. Instead, they give trusted users sudo permission to run specific commands as root without needing the root password. This approach leaves a record of who ran what command and when, which is useful for security and troubleshooting.

Testing the new password before you log out

After you change the root password, test it before you close your terminal session. Open a new terminal tab or window and try to log in as root using the new password, or run a sudo command that requires a password. This confirms the change worked and that you can still access the root account.

If you are changing the password remotely over SSH, test it in a separate SSH session before closing your current one. This way, if something went wrong, you still have a working connection and can fix it. Locking yourself out of root access on a remote server is a serious problem that may require physical access to fix.

Frequently Asked Questions

Do I need to restart the computer after changing the root password?

No. The password change takes effect when ready. Any new login attempts will use the new password, but existing terminal sessions and logged-in users are not affected. You only need to restart if you want to test that the new password works at the login screen.

What happens if I forget the new root password?

You will need to boot into recovery mode or single-user mode to reset it. On Ubuntu, hold Shift during startup and select recovery mode. On other distributions, the process differs — check your system's documentation. If the computer is remote and you have no physical access, you may need to contact your hosting provider or system administrator.

Can I change the root password if I only have sudo permission for specific commands?

Only if your sudo configuration includes permission to run the passwd command. Check with your system administrator. If you can run sudo passwd root without being asked for a password, you have permission. If sudo asks for your password and then refuses, your configuration does not allow it.

Is it safe to use a straightforward password for root if I do not use the root account often?

No. Even if you rarely log in as root, the password should be strong. Anyone with physical access to the computer or a network connection can attempt to guess it. A weak root password is a common entry point for attackers, regardless of how often the account is used.

Should I write down the root password somewhere?

Write it down and store it in a find, physical location — a locked safe or vault, not a text file on the computer. For production servers, consider using a password manager that your team controls, or a secrets management system. Never email the password or store it in a shared document.