chpasswd

user managementLinux
The chpasswd command is one of the most frequently used commands in Linux/Unix-like operating systems. chpasswd Update passwords in batch mode

Quick Reference

Command Name:

chpasswd

Category:

user management

Platform:

Linux

Basic Usage:

chpasswd [options] [arguments]

Common Use Cases

  • 1

    Batch password management

    Change passwords for multiple users at once

  • 2

    System administration

    Manage user passwords in bulk operations

  • 3

    User provisioning

    Set initial passwords for new user accounts

  • 4

    Password synchronization

    Synchronize passwords across multiple systems

Syntax

chpasswd [options]

Options

Option Description
-c, --crypt-method METHOD Use the specified method to encrypt the passwords (DES, MD5, NONE, SHA256, SHA512)
-e, --encrypted Supplied passwords are already encrypted
-m, --md5 Use MD5 encryption instead of DES
-R, --root CHROOT_DIR Directory to chroot into
-s, --sha-rounds ROUNDS Number of SHA rounds for the SHA256/SHA512 crypt algorithms
-h, --help Display help message and exit

Examples

How to Use These Examples

The examples below show common ways to use the chpasswd command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Change passwords for multiple users using a file
echo "user1:newpassword1
user2:newpassword2 user3:newpassword3" | sudo chpasswd
Change passwords with encryption specified
echo "user1:newpassword1" | sudo chpasswd -e
Use a specific encryption method
echo "user1:newpassword1" | sudo chpasswd -c SHA512
Read user/password pairs from a file
sudo chpasswd < user_passwords.txt

Advanced Examples:

Change password for a single user with MD5 encryption
echo "user1:newpassword1" | sudo chpasswd -m
Use with a script to update many accounts
cat /path/to/userlist.txt | sudo chpasswd
# Create a password update script #!/bin/bash
Generate password file
for user in $(cat userlist.txt); do
echo "$user:$(openssl rand -base64 12)" >> passwords.txt done
Update passwords
sudo chpasswd < passwords.txt

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

The chpasswd command is used to update passwords for multiple user accounts in batch mode. It's particularly useful for system administrators who need to change passwords for many users at once.

Important security considerations:

  • Using chpasswd with plain text passwords in scripts or command lines may expose passwords in process listings or shell history.
  • It's recommended to use encrypted passwords (-e option) when possible.
  • Modern systems should use SHA256 or SHA512 encryption methods rather than the older DES or MD5.
  • The command requires root privileges to change user passwords.
  • The input format must be "username:password" with one entry per line.

When using chpasswd in scripts, consider using process substitution or temporary files with appropriate permissions to minimize security risks.

Common Use Cases

Batch password management

Change passwords for multiple users at once

System administration

Manage user passwords in bulk operations

User provisioning

Set initial passwords for new user accounts

Password synchronization

Synchronize passwords across multiple systems

Automated user management

Automate password changes in scripts

Related Commands

These commands are frequently used alongside chpasswd or serve similar purposes:

Use Cases

1

Batch password management

Change passwords for multiple users at once

2

System administration

Manage user passwords in bulk operations

3

User provisioning

Set initial passwords for new user accounts

4

Password synchronization

Synchronize passwords across multiple systems

5

Automated user management

Automate password changes in scripts

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the chpasswd command works in different scenarios.

$ chpasswd
View All Commands