Table of Contents
Method 1 of 2:
With the Current Root Password
-
Images 1 of How to Change the Root Password in Linux Open a terminal window. To do so, press Ctrl+Alt+T,[1] which will open a new terminal window with a command prompt in most Linux desktop environments.- If you're not using a desktop environment, you're already at a command prompt, so proceed to the next step.
-
Images 2 of How to Change the Root Password in Linux Type su at the command prompt, and press ↵ Enter.[2] A Password: line will open below the command prompt. -
Images 3 of How to Change the Root Password in Linux 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, run su and try again.
- Passwords are case-sensitive.
-
Images 4 of How to Change the Root Password in Linux Type passwd and press ↵ Enter. An Enter new UNIX password: line will appear below the prompt. -
Images 5 of How to Change the Root Password in Linux Type a new password and press ↵ Enter. The password you type will not appear on the screen. -
Images 6 of How to Change the Root Password in Linux Retype the new password and press ↵ Enter. You will see a message that reads 'password updated successfully.' -
Images 7 of How to Change the Root Password in Linux Type exit and press ↵ Enter. This will log you out of the root account.
Method 2 of 2:
Without the Current Root Password
-
Images 8 of How to Change the Root Password in Linux Restart your computer. -
Images 9 of How to Change the Root Password in Linux Press E at the Grub menu.[3] 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.
- This method works for most popular Linux distributions (Ubuntu, CentOS 7, Debian). 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.
-
Images 10 of How to Change the Root Password in Linux Scroll to the line that begins with linux /boot. Use the ↑ and ↓ keys to do so. 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 rather than linux.
-
Images 11 of How to Change the Root Password in Linux Move the cursor to the end of the line. Use the →, ←, ↑, and ↓ keys to place the cursor right after ro. -
Images 12 of How to Change the Root Password in Linux Type init=/bin/bash after ro. The end of the line should now look like this:ro init=/bin/bash.- Note the space between
roandinit=/bin/bash.
- Note the space between
-
Images 13 of How to Change the Root Password in Linux Press Ctrl+X. This tells the system to boot directly to a root-level command prompt in single-user mode. -
Images 14 of How to Change the Root Password in Linux Type mount –o remount,rw / at the prompt and press ↵ Enter. This mounts the file system in read-write mode. -
Images 15 of How to Change the Root Password in Linux Type passwd at the prompt and press ↵ Enter. Since booting into single-user mode gives you root access, there's no need to pass additional parameters to the passwd command. -
Images 16 of How to Change the Root Password in Linux Type a new root password and press ↵ Enter. The characters you type won't be displayed on the screen. This is normal. -
Images 17 of How to Change the Root Password in Linux Retype the new password and press ↵ Enter. When the system confirms you've re-entered the same password, you'll see a message that reads 'password updated successfully.' -
Images 18 of How to Change the Root Password in Linux Type reboot –f and and press ↵ Enter. This command reboots the system normally.
3.7 ★ | 3 Vote