How to change paasword in Linux is a basic thing that needs to know when you are working in a Linux environment, I would say that should be the first command you need to know before knowing about the more complex commands. This article is mainly focusing on changing the password in a Linux system, another thing we will discuss here is how to force users to change the password next time their login.
This should work in any Linux distribution like Debian, Ubuntu, or CentOS
You can change the password in a Linux environment for a particular user using passwd utility.
Encrypted password and all the password related information will be saved in the /etc/shadow file. You can view the information by providing the below command in the terminal, You might have to login as admin (root) to access the file.
$ cat /etc/shadow
Let’s see how to change password in Linux if you are a regular user, the regular users can change their own password only, The root user and the users with sudo (superuser) permission can change other user’s passwords and define how the password can be used or changed.
The most important thing is when you are changing a password use a strong and unique one. It is the first and basic thing you can do to secure your account. Usually, a strong password has at least 16 characters and contains at least one uppercase letter, one lowercase letter, one number, and one special character.
Change your User Password
You can run the passwd command to change your own password.
$ passwd
When you enter the above command you will be prompted to enter your current password. If your password is correct then you can enter your new password and there will be another prompt to retype the password to confirm.
When you enter the wrong password, it will again prompt you to enter the current password. If it is the wrong command will exit with an error.
Change the password in Linux for other users As we discussed earlier only root users or users with sudo permission can change the other users’ passwords. In the below example we have logged as root user and trying to change the password of user bob, You have to run the passwd command followed by user name to change the password. In this example, we have to provide bob after the passwd command. $ passwd bob
The below example shows if you are not logged in as root, but logged in as a user with the sudo permission and change the password. In this case, you have to enter the sudo password of the logged-in user while running the command.
Force user to Reset the password at next login
In Linux by default, passwords are set to never expire. To force a user to change their password at the next login attempt use command passwd with --expire followed by the username of the user.
From the root user
$ passwd --expire bob
From user with sudo permission.
$ sudo passwd --expire bob
After setting the password expiration user will prompt to change the password once they have provided their current password on their next login as below.
Hope you have gained some knowledge about How to change password in Linux. These are the basic password-related stuff in Linux and if you need to know anything other than this please put a comment and I will answer your questions. If I have forgotten to include something here please notify me and I will update them accordingly.
No comments:
Post a Comment