20081022 usage of chpasswd - plembo/onemoretech GitHub Wiki

title: Usage of chpasswd link: https://onemoretech.wordpress.com/2008/10/22/usage-of-chpasswd/ author: lembobro description: post_id: 439 created: 2008/10/22 08:19:19 created_gmt: 2008/10/22 08:19:19 comment_status: open post_name: usage-of-chpasswd status: publish post_type: post

Usage of chpasswd

The chpasswd utility is one of those little known wonders of Unix system administration.

In a nutshell, it allows you to make password changes on a Unix system in bulk.

There’s an interactive mode, where you simply enter the command as root, type in your list of colon-separated user names and passwords (in clear text) and then hit Control-D to commit. Like this:

`

[root@localhost ~]# /usr/sbin/chpasswd
test1:hello
test2:hello
test3:hello
^D
[root@localhost~]

`

The batch mode is more interesting, in that it will take a similar list from standard output. As a practical matter that means making a colon-separated list of one user name and password per line and then issuing the following command:

cat testpw.txt | /usr/sbin/chpasswd

The pipe operator is absolutely essential to making this work, as is the use of cat.

(I use the full path to the executable as a matter of habit, root’s environment should contain /usr/sbin — well, it should.)

Now all I have to do is write a script to invoke it remotely.

Copyright 2004-2019 Phil Lembo