What's the difference between 'passwd' and 'chpasswd'?
From man chpasswd
:
'This command is intended to be used in a large system environment where many accounts are created at a single time.'
passwd
is (in my experience) normally used interactively for a single user.
See man pages for both of them:
NAME
chpasswd - update passwords in batch mode
SYNOPSIS
chpasswd
[options]DESCRIPTION
The
chpasswd
command reads a list of user name and password pairs from standard input and uses this information to update a group of existing users. Each line is of the format:user_name:password
NAME
passwd - change user password
SYNOPSIS
passwd
[options] [LOGIN]DESCRIPTION
The
passwd
command changes passwords for user accounts. A normal user may only change the password for his/her own account, while the superuser may change the password for any account.passwd
also changes the account or associated password validity period.
In a nutshell:
passwd
checks if the STDIN (file descriptor 0) is attached to the terminal, usingisatty(0)
. If not,passwd
would bail out i.e. you can only work withpasswd
interactivelychpasswd
, on the other hand, is designed to read (username and) password from STDIN, and is called the batch mode (creates/updates multiple user credentials at once). It reads password(s) (in clear text by default), and username(s) from STDIN, given in the formatuser_name:password
, with newline separating the entries