How to change root password on a Linux server

In order to set a new root password, make sure you’re logged into the correct server and the session is running as root.

root

Then, run a “passwd root” to invoke the password change command. Enter the new password twice to successfully change the password.

root2

This indicates that root password was successfully changed. The same procedure can be applied to any user on the server by replacing root with any other username.