Knowledgebase

How to Change Root Password in Linux?

In Linux, the root user is the most powerful account on the system. It has complete control over files, services, users, and security settings. Because of this, the root password protects your entire server.

If your root password is weak, shared, or outdated, your system becomes vulnerable. That’s why changing the root password regularly is a good security practice, especially for VPS, Dedicated Servers, or production environments.

In this guide, we will walk through step-by-step methods to change the root password in Linux. Each method is simple and clearly explained, so you can follow it without confusion.

Let’s get started!


Also Read: How to Kill a Process in Linux?


Simple Methods to Change Root Password in Linux

 Method 1: Change Root Password When Logged in as Root

This method is used when you already have access to the root account:

When to Use This Method:

  •  You can log in as root.
  •  You know the current root password.
  •  You just want to update it for security reasons.

Step-by-Step Process:

➔ Firstly, you have to log in as Root via SSH:

Copied!
ssh root@your_server_ip

In this, replace your_server_ip with your actual server IP address.

➔ After that, you will be asked to enter the current root password (If you are already inside the server (terminal access), make sure you are logged in as root).

You can confirm by running:

Copied!
whoami

★ If it shows root, you are logged in as root.

➔ After that, you have to run the password command:

Copied!
passwd

★ What This Command Does:

The passwd command is used to change user passwords in Linux. Since you are logged in as root, the root password will be changed by default.

➔ Now, you have to enter the new password, as you will see this:

Copied!
New password:

Here, you have to type your new password and press Enter.

★ Important:

    You will not see characters while typing (this is normal for security).

    So you have to type carefully.

Then you will be asked:

Copied!
Retype new password:

You have to re-enter the same password.

➔ If both passwords match and meet system requirements, you will see:

Copied!
password updated successfully

Your root password has been changed!


Also Read: How to Rename a Folder in Linux​?


 Method 2: Change Root Password Using sudo (Without Logging in as Root)

This method is used when:

  •  You are logged in as a normal user.
  •  Your user has sudo privileges.
  •  Direct root login is disabled.

Step-by-Step Process:

➔ Firstly, you have to log in as a Sudo User

Copied!
ssh username@your_server_ip

In this, replace username with your actual username & your_server_ip with your Server IP Address.

➔ In that, you have to use sudo to change the root password by running the following command:

Copied!
sudo passwd root

What This Command Means:

  •  sudo → Run command with administrative privileges.
  •  passwd → Change password.
  •  root → Specify that we want to change root’s password.

➔ You will now be asked to enter your current user password, not the root password. This is for verification!

➔ Now the system will ask:

Copied!
New password:

In that, you have to enter the new root password & then confirm it.

If successful, you will see:

Copied!
passwd: password updated successfully

The root password has now been changed.


Also Read: How to Check Memory in Linux?


Best Practices for Root Password Security

  •  Use 12–16+ characters.
  •  Avoid simple passwords like admin123.
  •  Use a mix of uppercase, lowercase, numbers, and symbols.
  •  Avoid sharing root login.
  •  Consider disabling root SSH login and using sudo instead.

Conclusion

Changing the root password in Linux is not complicated, but it is one of the most important security tasks for any server administrator. Whether you are updating it for security reasons, using sudo access, or recovering from a forgotten password through recovery mode, each method serves a specific purpose.

Understanding not just the commands but also why each step is performed helps you manage your server with confidence. A strong and properly managed root password protects your entire system from unauthorized access.

Make it a habit to review and update your root credentials regularly because a secure root account means a secure Linux server.