Configure Linux Users’ Passwords with chpasswd Command

This guide intends to teach you to Configure Linux Users’ Passwords with the chpasswd Command. The chpasswd command is a Linux command-line utility that is used to change passwords for multiple user accounts. It’s important to note that the chpasswd command is typically used in scripts or automation tasks where there is a need to change passwords for multiple users non-interactively. It’s commonly used by system administrators to manage user accounts efficiently and securely.

Learn To Configure Linux Users’ Passwords with chpasswd Command

To complete this guide, you must access your Linux server as a root or non-root user with sudo privileges. You can check the Orcacore website and look for Linux Servers Initial Setup Guides.

Then, follow the steps below to use the chpasswd command in the Linux terminal with Examples.

Step 1 – The General Syntax of chpasswd Command

The general syntax of the chpasswd command is as follows:

chpasswd [options]

In the above command, you can use different options to customize your chpasswd behavior.

To get options and help, you can use the following -h option:

chpasswd -h

In your output, you will see:

The General Syntax of chpasswd Command

Step 2 – Change Users’ Passwords via chpasswd Standard Input

At this point, you can run the chpasswd without any option to change the user’s password from the standard input.

chpasswd

For example, we update the passwords for the following existing users as shown below:

orca:newpassword1
olivia:newpassword2

Once you are done, press ctrl+d to complete your task.

Also, you can use the -c option to change your encryption method. By default, chpasswd uses the PAM method. For example, to change it to None, you can run:

chpasswd -c NONE

Step 2 – Update Users’ Passwords via chpasswd Password File

Another method to update the users’ passwords is to use a file with the current users and their updated passwords.

First, you need to create a file with your desired text editor like Vi editor or Nano editor:

vi mypasswords.txt

At the file, you must add the users with the new passwords in Linux servers as shown below:

user1:newpass1
user2:newpass2
user3:newpass3

When you are done, save and close the file.

Then, you can verify the password file content with the command below:

cat mypasswords.txt

At this point, you must run the chpasswd command in Linux to redirect data from the mypasswords.txt file:

chpasswd < mypasswords.txt

This will read your passwords from the file.

Conclusion

The chpasswd command provides an efficient way to update passwords for user accounts individually or in bulk. By accepting username and password pairs from standard input or a specified file, you can easily update your users’ passwords in Linux. Hope you enjoy it.

Also, you may like to read the following articles:

Maximize Sudo Session Duration in Linux

Spaces in Filename on Linux with Examples

4 Linux Commands to Get Public IP Address

Hide Files and Directories in the Linux Terminal Command Line

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!