Open In App

chpasswd command in Linux with examples

chpasswd command is used to change password although passwd command can also do same. But it changes the password of one user at a time so for multiple users chpasswd is used. Below figure shows the use of passwd command. Using passwd we are changing the password of the guest user. Here first you have to enter the password of the currently signed user and then you change the password of any other user. One must have administrator privileges.



chpasswd command reads a number of username and password which are separated by colon using standard input or file, and then encrypt as per the options.

Syntax:



$chpasswd
user1:user1_password
user2:user2_password
user3:user3_password

Note: After completion please press ctrl+d to exit from the command. As soon as ctrl + d is pressed password gets changed.

A simple text file can also be used to store username and password and then use them to change the password.

$cat > pass.txt
user1:user1_password
user2:user2_password
user3:user3_password

Then provide this to chpasswd command.

$chpasswd < file_name.txt

Options:

Example: The encryption algorithm can also be applied to the password.

$chpasswd -c SHA512
user1:user1_password
user2:user2_password
user3:user3_password

or

$chpasswd --md5
user1:user1_password
user2:user2_password
user3:user3_password

Note: Both are a different type of encryption algorithm

Article Tags :