13

I read description of these command from a book,
passwd:

Changes the password for an existing user.

chpasswd:

Reads a file of login name and password pairs, and updates the passwords.

It seems these command doing same jobs. Is there a difference between them?

EDIT:

I want to learn when we use them which file(s) change. Do they change same file or different file? If they change different file(s), what are they?

  • 2
    /etc/password contains user account information. /etc/shadow contains encrypted passwords. I believe those are the only files that are relevant. You could change a password by manually editing those files, but it would be very awkward. – SauceCode Feb 16 '17 at 13:33
18

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.

7

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.

6

In a nutshell:

  • passwd checks if the STDIN (file descriptor 0) is attached to the terminal, using isatty(0). If not, passwd would bail out i.e. you can only work with passwd interactively

  • chpasswd, 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 format user_name:password, with newline separating the entries

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.