chpasswd Command in Linux with Examples

This tutorial explains Linux “chpasswd” command, options and its usage with examples.

chpasswd – update password file in batch

Description :

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
user_name:password
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.

Usage :

chpasswd [options]

Options :

advertisement
advertisement

-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.
-e, –encrypted
Supplied passwords are in encrypted form.
-S, –stdout
Report encrypted passwords to stdout instead of updating password file.
-h, –help
Display help message and exit.

Examples :

1. To set passwords for users from the command line, type:

# chpasswd

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:

advertisement
user1:passwd1
user2:passwd2
...

3. To use another encryption method:

# chpasswd -ec MD5

Now MD5 encrypted passwords must be given.

advertisement

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.