Most new Linux admin users of CentOS 8 do not know how to reset or change the sudo password from the command line environment. It is a good practice for security reasons to regularly change the password of each system user. This habit is important for superuser, who has special privileges to perform all sensitive tasks under CentOS 8. Only root or a superuser can change the password for any other user account. Normal users can only change their own passwords. A user’s password can be changed under CentOS 8 using the ‘passwd’ command.
This article demonstrates how a root user can change its own password on a CentOS 8.
The following steps are necessary to change the sudo password from the command line:
Step 1: Open Terminal
To change the sudo user password, you must first open the command line or terminal on your CentOS 8 system. To do this, you can either use the key combination “Ctrl + Alt + t” to open the terminal, or you can access it from the application launcher search bar as follows:
You can open the application launcher search bar by pressing the window key or superscript key on the keyboard.
Step 2: Log in as admin or root user
The root user can only change his own password. Therefore, log in as the root user on your CentOS 8 system. To do this, you need to type the following command in the terminal:
$ sudo -i
The system will prompt you to enter the password of your root account. Enter the password and press “Enter” to log in as the root user.
You have logged in as the root user on your CentOS 8 system. You can see this in the image above.
Step 3. Change the sudo password using the passwd command
Now that you have logged in as the root user, you can change the root account password by running the passwd command as follows:
After running the passwd command in the terminal, the system alerts you that you are changing the current root user password and prompts you to enter the new root user password. You enter the new password and press ‘Enter’, the system will prompt you again to enter the new password. Enter the above password again and press ‘Enter’. The terminal will display a confirmation message that all authentication tokens have been successfully updated, which means that the password has been successfully updated.
Now use the newly updated password for your root account in all software installations and file configuration operations that require root authorization.
Step 4: Log off or terminate the root terminal session
Now that you have changed the root password, you can log out of the root user prompt by entering the following command:
After running the above command, the logout status will be displayed on the terminal, which means that you have now been logged out or exited from the root account.
There is another alternative to change the root user’s password. You use the following command on the terminal, through which you log in as the root user and enter the root account password. With a single command, you can change the root user’s password in this way.
$ sudo passwd root
After running the above command, a password change notification will appear on the terminal. Now enter the new password and press “Enter”. Enter the newly selected password again and press “Enter” again. After that, a message will appear that all authentication tokens have been successfully updated, which means that the root password has been changed.
In this article, you learned how to change the root account password using the terminal on CentOS 8. I hope that you are now able to change the password of your root user account, which will help you to protect your system from malicious activities. Please give us your feedback via the comments.