This tutorial explains Linux “chpasswd” command, options and its usage with examples.
chpasswd reads a file of user name and password pairs from standard input and uses this information to update a group of existing users. Without the -e switch, the passwords are expected to be cleartext. With the -e switch, the passwords are expected to be in encrypted form. Each line is of the format
The named user must exist. The supplied password will be encrypted as necessary, and the password age updated, if present.
This command is intended to be used in a large system environment where many accounts are created at a single time.
-c, –crypt-method METHOD
Use the specified method to encrypt the passwords. The available methods are DES, MD5, NONE, and SHA256 or SHA512 if your libc support these methods. By default, PAM is used to encrypt the passwords.
Supplied passwords are in encrypted form.
Report encrypted passwords to stdout instead of updating password file.
Display help message and exit.
1. To set passwords for users from the command line, type:
Followed by entering username:password pairs, one pair per line. Enter CTRL+D when finished.
user1:passwd1 user2:passwd2 CTRL+D
2. To set passwords for users contained in a file named mypwdfile, type the following:
# cat mypwdfile | chpasswd
Note that mypwdfile must contain username:password pairs; one pair per line. For example:
user1:passwd1 user2:passwd2 ...
3. To use another encryption method:
# chpasswd -ec MD5
Now MD5 encrypted passwords must be given.
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.