Change the Root Password in Linux
To change the root password in Linux, you’ll need to run the “passwd” command from a root-level command prompt. If you know the current root password, you can use “su” to access the root account and run “passwd” right from a terminal window. If you’ve forgotten the root password, however, you’ll need to boot into single-user mode first, in order to get permission to run “passwd.” Learn how to change the Linux root password from the command line when booted normally or in single-user mode.
Contents
[hide]Steps
With the Current Root Password
- Press Ctrl+Alt+T to open a terminal window. As long as you know the current root password, you can change it right from the desktop. This keyboard shortcut will open a new terminal window with a command prompt in all Linux desktop environments.
- If you don’t have the current root password, see .
- If you’re not using a desktop environment, you’re already at a command prompt, so just continue to the next step.
- Type
su
at the command prompt, then hit ↵ Enter. A new line will open beneath the command prompt that says “Password:” - Type the current root password, then press ↵ Enter. When the password is accepted, you’ll be brought back to the command prompt as the root user.
- If you type the password incorrectly, just run
su
again and retry. - Passwords are case-sensitive.
- If you type the password incorrectly, just run
- Type
passwd
, then press ↵ Enter. A new line will open beneath the command that says, “Enter new UNIX password:” - Type a new password, then press ↵ Enter. The password you type will not appear on the screen, but you’ll be prompted to type it a second time to confirm.
- Retype the new password, then press ↵ Enter. You will see a message that says “password updated successfully.”
- Type
exit
and then press ↵ Enter. This will log you out of the root account.
Without the Current Root Password
- Start the computer and press the E key at the Grub menu. This method will work for most popular Linux distributions (Ubuntu, CentOS 7, Debian).If you’ve lost the root password, you can reset it in single-user mode. The Grub menu appears right after you turn on the computer. In most cases, it only stays on the screen for a few moments.
- If you don’t press E before the Grub menu disappears, reboot and try again.
- There are many distributions of Linux, some more obscure than others. If you’re not able to get to single-user mode with this method, check your distribution’s website for instructions specific to your system.
- Use the ↑ ↓ keys to scroll to the line that begins with “linux /boot”. This is the line you’ll need to modify in order to boot into single-user mode.
- In CentOS and some other distributions, the line may begin with “linux16” instead of just “linux.”
- Use the → ← ↑ ↓ keys to move the cursor to the end of the line. The line ends with
ro
, so place the cursor right after that. - Type
init=/bin/bash
at the end of the line. The end of the line should now look like this:ro init=/bin/bash
.- Note the space between
ro
andinit=/bin/bash
.
- Note the space between
- Press Ctrl+X to boot into single-user mode. This will tell the system to boot directly to a root-level command prompt.
- Type
mount –o remount,rw /
at the prompt, then press ↵ Enter. This mounts the file system in read-write mode. - Type
passwd
at the prompt, then press ↵ Enter. Since booting into single-user mode gives you root access, there’s no need to pass additional parameters to the “passwd” command. - Type a new password for the root user, then press ↵ Enter. Note that you won’t see the characters you type on the screen. This is normal.
- Type the new password again when prompted, then press ↵ Enter. When the system confirms you’ve re-entered the same password, you’ll see a message that says “password updated successfully.”
- Type
reboot –f
and then press ↵ Enter. This command reboots the system normally.
Tips
- Make sure your passwords are 8 characters or more and contain a mix of letters (upper and lowercase), numbers and symbols.
- To change the password for another user, "su" to root and type "passwd <username>".
Related Articles
- Install MySQL on Fedora
- Change Your Password in Linux Using Terminal
- Set up a Wireless Network in Linux Via the Command Line
- Manage Users in Linux
- Reset Forgotten Password in Linux