chpasswd command in Linux basically stands for Change Password, and allows users to change the password for various user accounts. however, the users can also use passwd command as well to do same things. But, with the help of chpasswd command, the users can change password of multiple users at a time easily.
Means, using chpasswd can read a number of username and password that can be separated by a colon using either through an input or through a specified file, and change the passwords for those according to specified options.
Table of Contents
Syntax of chpassword command
chpasswd user1:password1 user2:password2 user3:password3
Do make sure to press CTRL + D key combination to exit the command and take the changes in effect.
Options available to use with chpasswd command
- -c | -crypt-method Method_Name: Used for the crypt method such as DES, MD5, SHA256, SHA512, etc.
- -e | -encrypted: Used for supplying encrypted passwords.
- -h | -help: Displays help details and options
- -m | -md5: Used for encrypting clear text passcodes using MD5 algorithm.
- -s | -sha-no_of_rounds: allows to specify number of rounds for SHA crypt algorithm.
Examples of chpasswd command
1: Changing password of a user named servonode:
sudo chpasswd [sudo] password for current_user: Enter_Password servonode:amenda9456945
2: Changing password of user through text file
create a text file first named pass.txt and store the password for different users.
sudo nano pass.txt user1:password1 user2:password2 user3:password3
Save the file and provide this to chpasswd command.
Chpasswd < pass.txt
3: Applying encryption algorithm with chpasswd command
chpasswd -c SHA512 user1:password1 user2:password2 user3:password3 or chpasswd --md5 user1:password1 user2:password2 user3:password3