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

Doesn't the passwd command require user input? I see nothing in your code that would be passing along the old password, new password to the passwd program. In fact, I see nowhere that a new password is even captured or stored. My suspicion is that you probably would be better off using expect for what you want to accomplish.

The purpose of the program was to demonstrate that passwd doesn't even prompt you via stderr for a password. Either old or new. I'm considering using expect rather than doing it this way however if passwd doesn't provide any prompts I suspect expect will have similar difficulties.

FYI... the full program I've built does provide a couple of routines asking for old/new password. Once I have it working properly I hope to make it available so people would know how to do this in Perl.

Replies are listed 'Best First'.
Re^3: Net::SSH::Perl and Passwd
by eldapo (Initiate) on Oct 22, 2008 at 18:52 UTC
    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); }