One of the advantages of Linux over other operating systems is the need to enter a password for almost any change we want to make to the system. This, something that may seem like a nuisance, also means greater security for us. That is why we may want to change our password in Linux to make it easier for us to remember. To do this we must use the passwd command from the Terminal.
To be able to install or uninstall a program, as well as to enter commands in the Terminal, we will need our Linux root password, and it is not the same as the login password, so it is important that we change it and have one that is more convenient for us. easy to memorize. Password is used to update a user’s authentication token (password) stored in the /etc/shadow file, while passwd is used to change user and group accounts.
A normal user can only change the password of his own account, while the superuser (or root) has the ability to change the password of any account. The passwd command also changes account information such as the user’s full name, the user’s login shell, or the password’s expiration date and range.
The way to implement change password in Linux should work properly on any distribution like Alpine, Arch, Ubuntu, Debian, RHEL, Fedora, Oracle CentOS, SUSE/OpenSUSE and other popular distros.
Linux and passwords
Linux operating systems are considered by experts to be among the most secure in the world, mainly due to the way in which their processes are handled. When using each system, at many times we will depend on the use of the password, managing it in a similar way to other systems such as Windows or macOS.
But there is something in which they differ, and that is by having two important directories when managing passwords.
On the one hand, there are the /etc/passwd files, where all system users are stored, showing at all times to which system group they belong. In this way, although we see many users, it is possible that only with some we can log in. It is possible to see its content through the command:
cat /etc/passwd
On the other hand, we have the /etc/shadow file that is related to passwords. Here we can see all passwords encrypted by users and check if they have an SSH key. It is possible to see its content through the command:
cat /etc/shadow
Set up a strong security password
Configuring our Linux systems with a strong and secure password is something basic that surely not all users comply with. That is why it is important to have a good key policy configured to keep our privacy and security safe. For this, it is important to create robust passwords that are not found in the dictionary and that may have some complexity to decipher.
It is also important to avoid common passwords such as:
- Words appearing in a dictionary
- Your name and last name
- pet names
- Names of children or spouses
- License number
- Date of birth
- Home or office address
It is important that our password has at least 12 characters, includes upper and lower case letters and even special characters. Along with this, it is also important that we can remember it with some ease, since in Linux it is used regularly for any change we want to make.
Change the password to a root user
When we talk about a root account in Linux, we do it about the one that has the capacity to have all the permissions and privileges. On many occasions it will be necessary to have root access to be able to execute certain commands, especially when they affect the system.
The first thing we must do is open the Terminal, for which in most distributions it is enough to press the key combination Ctrl + Alt + T.
Now we must authenticate ourselves as root, for which we must establish the following command and press Enter:
su –
Next, we need to set our password and if we are successfully logged in as root, the system should end with # instead of $.
Now to change the password we write the following command and press Enter:
sudo passwd root
Next, we have to type the new password and then confirm the new password. If everything has gone well, “passwd updated sucessfully” will appear. Now we can close the Terminal.
Change password on Linux
Next, we are going to see different ways to change the password in Linux from the Terminal.
for a user
In order to change our password in Linux as a user, we must enter the passwd command as follows:
$ paswd
It will then inform us that we are trying to change the password, so it will ask us to enter the current password first. Later we will write the new password and finally we write it again to confirm.
If we have carried out the steps correctly, finally the message “passwd: password changed correctly” will appear.
From another user account
To change the password of another user, we must first log in as root, for which we type:
su –
Later we write the following command to change the password of the softzone user:
# passwd softzone
Next, we type the new password for that user and confirm it. If everything has gone well, the message “paswd: password updated successfully” should appear. Once this is done we can close the Terminal.
For a user as administrator
As administrator of a Linux system we can change the password of any user that is added. To do this, the first thing will be to log in as root, for which we write:
su –
Later we write the passwd command followed by the username to which we want to change the password, for example, the softzone user. To do this we write:
passwd softzone
Now the system will ask us to write the new password for that user and we confirm it. If everything has gone well, the message “paswd: password updated successfully” should appear. If everything has gone perfectly, we can close the Terminal.