How to change the root user password from the command prompt in Linux?

If you haven't accessed your system as a root user in a while and haven't stored the login details, you may lose access to your system credentials. It's not an uncommon event; it's a typical issue that most Linux users have likely experienced previously. In such occurrences, you can readily modify or reset the password using either the command line or the Graphical User Interface (GUI).

However, what steps should be taken if there is a need to change or reset the root password?

This article provides instructions on changing the root password for your Linux system using three different methods.

Note: To update the root password, you should have the current root password, sudo privileges, or physical access to the system. It is advisable to store the new password(s) securely for future reference. 

In this article, we will discuss the following procedures:

1. Modify or reset the root password as the root user.

2. Modify or reset the root password as a sudo user.

It's important to note that all the commands in this article have been tested on the system. These commands were executed in the Terminal, accessible through the Ctrl+Alt+T key shortcut or by clicking on the applications>>system>> Terminal.

Let's start.

1. Modify or reset the root password as the root user.

If you have the existing root password and want to reset it, use the 'passwd' command. Follow these steps to change or reset the root user password:

To begin, log in as a root user by executing the following command in the Terminal:

$ su root

When prompted for the password, enter the current root password. Subsequently, observe the Terminal prompt change to '#,' indicating that you are now logged in as the root user.

Or you can directly Sign in to your server using SSH as the root user.

Most users forget their root passwords at some point. Especially if you haven't logged in as the root user for a long time, this is to be expected. But don't worry. We will guide how to reset a forgotten root password in Linux.

You must have either the current working root password or sudo privileges to change the root password,

Follow the below steps to change the root user password in Linux.

Step 1: Log in to your server via SSH as a root user.

Step 2: Enter the following command prompt to change the root password.

# passwd

It will ask you for a new password for the root user. First, enter the new password and press Enter. Then, re-enter the password and press Enter.

Upon entering the password, you will see a message that the password has been updated.

Choosing a strong password for the root user is crucial, as the root user has full privileges on the system and can make any changes. A strong password is complex for others to guess or crack using automated tools. It should be at least 8 characters long and contain a combination of upper and lower case letters, numbers, and special characters.

2. Modify or reset the root password as a sudo user.

Also, a standard user with sudo privileges can change the root password. Using the sudo command will allow you to run commands with root privileges even if you do not have access to the root user account or do not wish to switch to the root user.

You can change the root user password by following the steps given below:

Step 1: Type the following command in the terminal as a sudo user.

$ sudo passwd root

It will ask you for a new password for the root user. First, enter the new password and press Enter. Then, re-enter the password and press Enter.

Upon entering the password, you will see a message that the password has been updated.

Note: To change the root password, you must have either the current root password or sudo privileges.

It is also advised to save the new password(s) in a safe place to be accessed when needed.


Was this answer helpful?

« Back

chat