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

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 wil 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.

Change the Root password as 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