The “passwd” command in Linux is used to change a user’s password. It allows users to update their own passwords or, if executed by the system administrator or with appropriate privileges, change the password for another user.
Here is the basic syntax of the “passwd” command:
passwd [options] [username]
Some common options used with the “passwd” command are:
-l: Locks the user account by putting a “!” character at the beginning of the encrypted password field in the
-u: Unlocks a locked user account.
-d: Deletes the password for the specified user account.
-e: Forces the user to change their password on the next login.
If you execute the “passwd” command without any options or a username, it will prompt you to enter the new password for your own user account.
Practical example of how to use Linux passwd command
Sure! Here are some practical examples of how to use the Linux “passwd” command:
- To change your own password:
Running the “passwd” command without any options or a username will prompt you to enter the new password for your own user account. You’ll be asked to enter the current password and then provide a new password.
- To change another user’s password (as root or with appropriate privileges):
sudo passwd username
Replace “username” with the actual username of the user whose password you want to change. This command will prompt you to enter and confirm the new password for that user.
- To lock a user account:
sudo passwd -l username
This command locks the specified user account, preventing the user from logging in. Replace “username” with the actual username of the account you want to lock.
- To unlock a locked user account:
sudo passwd -u username
If a user account is locked, this command can be used to unlock it and allow the user to log in again. Replace “username” with the actual username of the locked account.
- To force a user to change their password on the next login:
sudo passwd -e username
This command sets an “expired” status for the user’s password, forcing them to change it upon their next login. Replace “username” with the actual username of the user.
Remember to execute these commands with appropriate privileges, such as using “sudo” or being logged in as the root user, when changing passwords for other user accounts or performing administrative tasks.