How to use the passwd command in Linux?
The passwd command in Linux is used to change a user’s password and has several common uses.
- Change the current user’s password:
- change password
- After executing the command, the system will prompt you to enter the old password of the current user, and then request to enter the new password twice for confirmation.
- Change the passwords of other users (requires root privilege):
- Change the password for the specified username.
- After running the command, the system will prompt for the password of the root user, and then require entering the new password twice for confirmation.
- Change password of other users and force them to change their password next time they log in (root permission required):
- Expire the password of a user with the following command: sudo passwd –expire
- After running the command, the system will ask for the root user’s password, and then require input of a new password twice for confirmation. This command will expire the user’s password, and the next time the user logs into the system, they will be asked to change their password.
- Disable user password (requires root permission):
- Lock the password for the specified username using the “sudo passwd –lock
” command. - After running the command, the system will prompt for the password of the root user, and then disable the password of the specific user, who will not be able to log into the system using password authentication.
- Unlock user password (root permission required)
- Unlock the password for the specified user by running the following command: sudo passwd –unlock
- After running the command, the system will prompt for the root user’s password, then it will unblock the specified user’s password, allowing them to log in to the system using password authentication.
Please ensure you have sufficient permissions when using the passwd command to change a user’s password, and make sure the password you input is secure.