How to Change Root Password on CentOS Linux via Command Line
Before we go any further, this is not to reset your root password when you have lost or forgotten it. This is to change your current root password to a new one. The guide below assumes you know your root password to begin with.
Operating System: CentosOS Linux
The steps to change your root password is a quick and easy one.
SSH to your server.
SSH root@192.168.1.1 (replace with server IP)
Enter current password when prompted
Once logged in successfully, use the following command line
sudo passwd root
Follow the prompts that appear
New password: Retype new password: passwd: all authentication tokens updated successfully.
That’s it. It’s that easy. Now, make sure you don’t lose your new password. If you have to save this somewhere, keep it safe.