If you are a new Ubuntu admin user, you might want to know how to change the password in Ubuntu Linux server through bash shell or the command line. After all, it is a good security practice to change passwords for any user, especially the Super User, who can perform all sensitive operations on Ubuntu. Only a SuperUser or root can change the password for any user account. Other users can only change their own passwords.
User passwords are changed in Ubuntu using the passwd command.
In this article, we will explain how a root user can change his/her own password on a Ubuntu server.
We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.
Step 1: Open the Ubuntu command line
We need to use the Ubuntu command line, the Terminal, in order to change the sudo password. Open the Terminal either through the system Dash or the Ctrl+Alt+T shortcut.
Step 2: Log in as root user
Only a root user can change his/her own password. Therefore you need to log in as root first. Enter the following command to do so:
@ sudo -i
The system will prompt you to enter the current sudo password. Please enter the password and hit Enter.
Now you will be logged in as root user; you can see that indication in the command prompt.
Step 3: Change the sudo password through the passwd command
Now that you are logged in as root, you can change the passwd for the current (root) user by using the passwd command as follows:
When you enter the passwd command, the system will prompt you to enter the new UNIX root password. When you enter the new password and hit enter, the system will prompt you to retype the new UNIX root password. After doing so, the system will confirm that the password is updated successfully.
Now whenever you need to log in as root or perform any installation and configuration operation that requires root authorization, you will be using this new password.
Step 4: Exit the root login and then the Terminal
When you are done with changing the password, you can log out of the root prompt by entering the following command.
Once you are logged out, type the exit command again to exit the Terminal application.
A simple alternative is to enter the following command that lets you log in as root and enter the password changing command for root, in a single command:
$ sudo passwd root
When you enter the above command, the system will prompt you to enter the new UNIX root password. When you enter the new password and hit enter, the system will prompt you to retype the new UNIX root password. After doing so, the system will confirm that the password is updated successfully.
By the help of this article, you can change the password for sudo and make your system secure from any malicious activity time and again.