How to Change the Root User Password in Linux

Table of contents:

How to Change the Root User Password in Linux
How to Change the Root User Password in Linux
Anonim

This article shows you how to change the root account password of a Linux system either knowing the current one or not knowing this information.

Steps

Method 1 of 2: Knowing the Current Password

Change the Root Password in Linux Step 1
Change the Root Password in Linux Step 1

Step 1. Open a "Terminal" window

Using most Linux distributions just press the hotkey combination Ctrl + Alt + T. This will bring up a new "Terminal" window.

If you are not using a Linux distribution with a graphical interface, it means that you already have the command prompt available and you can proceed directly to the next step of the method

Change the Root Password in Linux Step 2
Change the Root Password in Linux Step 2

Step 2. Type the command su into the "Terminal" window and press the Enter key

A new prompt will appear with the following Password:.

Change the Root Password in Linux Step 3
Change the Root Password in Linux Step 3

Step 3. Type the current root user's password and press the Enter key

If the password entered is correct, you will be automatically returned to the command prompt of the "Terminal" window with the access rights of the root account.

  • If the password entered is wrong, run the su command again and try again.
  • Remember that passwords are case-sensitive, meaning they differentiate between uppercase and lowercase letters.
Change the Root Password in Linux Step 4
Change the Root Password in Linux Step 4

Step 4. Type the command passwd and press the Enter key

A new command line will be displayed with the following text Enter new UNIX password:.

Change the Root Password in Linux Step 5
Change the Root Password in Linux Step 5

Step 5. Type the new password you want to set and press the Enter key

For security reasons, no characters will appear on the screen while typing the password.

Change the Root Password in Linux Step 6
Change the Root Password in Linux Step 6

Step 6. Retype the password you just entered and press the Enter key

You will see a text message similar to the following "password updated successfully".

Change the Root Password in Linux Step 7
Change the Root Password in Linux Step 7

Step 7. Type the command exit and press the Enter key

This will log you out of the root account and the "Terminal" window will close.

Method 2 of 2: Without Knowing the Current Password

Change the Root Password in Linux Step 8
Change the Root Password in Linux Step 8

Step 1. Restart your computer

Change the Root Password in Linux Step 9
Change the Root Password in Linux Step 9

Step 2. Press the E key when the "Grub" menu appears on the screen

The "Grub" menu will appear on the screen as soon as the computer starts the boot process. In most cases it will only remain visible for a few moments.

  • If you don't press the E key before the "Grub" menu disappears from the screen, you will need to restart your system and try again.
  • This procedure works for most popular Linux distributions (Ubuntu, CentOS 7, Debian). However, there are many other versions of Linux some easier to use than others, so if you are unable to boot the system in "single user" mode, refer to the website of the distribution in use for more information on how to proceed.
Change the Root Password in Linux Step 10
Change the Root Password in Linux Step 10

Step 3. Scroll through the list to find the line of text that begins with the following wording linux / boot

To move the text cursor use the ↑ and ↓ keys on the keyboard. In order to start the system in "single user" mode, the indicated line of text must be changed.

Using the CentOS version of Linux and some other distributions you will need to search for the line of text starting with the word linux16 instead of linux

Change the Root Password in Linux Step 11
Change the Root Password in Linux Step 11

Step 4. Move the text cursor to the end of the indicated line

Use the →, ←, ↑ and ↓ keys to position the cursor exactly after the final characters ro.

Change the Root Password in Linux Step 12
Change the Root Password in Linux Step 12

Step 5. Type the following text init = / bin / bash after the characters ro

When you are done editing, the indicated line of text should look like this:

ro init = / bin / bash

  • Note that the characters

    ro

    and the text

    init = / bin / bash

  • they are separated by a blank space.
Change the Root Password in Linux Step 13
Change the Root Password in Linux Step 13

Step 6. Press the key combination Ctrl + X

This will instruct the operating system to start the command prompt in "single user" mode with the privileges of the root account.

Change the Root Password in Linux Step 14
Change the Root Password in Linux Step 14

Step 7. Type the following text mount –o remount, rw / as soon as the command prompt appears and press the Enter key

This will "mount" the entire file system, but in "read / write" mode.

Change the Root Password in Linux Step 15
Change the Root Password in Linux Step 15

Step 8. Type the command passwd and press the Enter key

Since the system is active in "single user" mode with the access rights of the root account, you will not need to re-enter the admin password to run the passwd command

Change the Root Password in Linux Step 16
Change the Root Password in Linux Step 16

Step 9. Type the new password you want to set and press the Enter key

For security reasons, no characters will appear on the screen while typing the password.

Change the Root Password in Linux Step 17
Change the Root Password in Linux Step 17

Step 10. Retype the password you just entered and press the Enter key

As soon as the operating system confirms that you have entered the same password, you will see a text message similar to the following "password updated successfully".

Change the Root Password in Linux Step 18
Change the Root Password in Linux Step 18

Step 11. Type the reboot -f command and press the Enter key

This will cause the system to boot normally.

Advice

  • The security password should be at least 8 characters long and should contain a combination of upper and lower case letters, numbers and symbols.
  • To change the login password of another user account, run the su command to get the root account rights, then type the passwd command.

Recommended: