in reply to Re^2: Net::SSH::Perl and Passwd
in thread Net::SSH::Perl and Passwd

Yes. The passwd utility is interactive. The chpasswd utility, on the other hand, will accept command line input. Syntax like this:

echo username:newpassword | /usr/sbin/chpasswd

chpasswd is available all most Linux distros as far as I know. On Red Hat it comes in the shadow-utils base system package. It's also supposed to be available on AIX 5.x and the BSD's. Inexplicably, it's missing from Solaris.

Here's a snippet that shows how it could be used in conjunction with Net::SSH::Perl as part of a mass password resetting script (FH is the handle for a file that contains target system and user data, including the new password -- to save space I've also removed error-checking code):

while (<FH>) { chomp; my ( $target, $username, $userpass ) = ( &parse_line(',',0,$_)); my $userstr = $username . "\:" . $userpass; print $target, " ", $userstr, "\n"; my $ssh = Net::SSH::Perl->new($target); $ssh->login($adminuser, $adminpass); my $cmd = "echo $userstr \| /usr/sbin/chpasswd"; my ($stdout, $stderr, $exit) = $ssh->cmd($cmd); }