Open In App

chpasswd command in Linux with examples

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • -c, –crypt-method Method_Name : This command option is used for the crypt method. The method can be DES, MD5, SHA256, SHA512 or NONE.
  • -e, –encrypted : It is used to supply the encrypted passwords.
  • -h, –help : Used to display the command options and messages.
  • -m, –md5 : It is used to encrypt the clear text password using the MD5 algorithm.
  • -s, –sha-no_of_rounds : Here you can give the number of rounds for the SHA crypt algorithm.

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


Last Updated : 15 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads