Forrest logo
back to the printf tool

chpasswd:tldr:0e9a7

chpasswd: Change the passwords for multiple users (The input text must not contain any spaces.).
$ printf "${username_1}:${new_password_1}\n${username_2}:${new_password_2}" | sudo chpasswd
try on your machine

This command is a combination of several utilities and is used to change the passwords for two different user accounts in a single command.

Let's break it down:

  1. printf "${username_1}:${new_password_1}\n${username_2}:${new_password_2}": This part uses the printf command to format and output the username and password input. In this case, it will print two lines in the format "username:password", with each pair separated by a newline character (\n). The ${username_1}, ${new_password_1}, ${username_2}, and ${new_password_2} are variables that hold the respective username and password values.

  2. |: This is a pipe symbol that allows the output of the printf command to be passed as input to the next command.

  3. sudo chpasswd: This is the second part of the command and uses the chpasswd command with elevated privileges (sudo). The chpasswd command is used to update the passwords for user accounts. It reads the username and new password pairs from the pipe and changes the passwords accordingly.

In summary, this command takes two sets of username and password pairs, formats them using printf, and then passes them as input to the chpasswd command with elevated privileges to change the passwords for the specified user accounts.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the printf tool