Here it is:
---
saturn:~/20_perl/ssh martin$ ./remoteinteract_voyager.pl
saturn.maki.dom: Reading configuration data ~/.ssh/config
saturn.maki.dom: Reading configuration data /etc/ssh_config
saturn.maki.dom: Connecting to voyager, port 22.
saturn.maki.dom: Remote protocol version 1.99, remote software version
OpenSSH_3.6.1p1+CAN-2004-0175
saturn.maki.dom: Net::SSH:
erl Version 1.25, protocol version 1.5.
saturn.maki.dom: No compat match: OpenSSH_3.6.1p1+CAN-2004-0175.
saturn.maki.dom: Connection established.
saturn.maki.dom: Waiting for server public key.
saturn.maki.dom: Received server public key (768 bits) and host key
(1024 bits).
Argument "ssh-rsa" isn't numeric in numeric eq (==) at
/System/Library/Perl/5.8.1/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line
4.
saturn.maki.dom: Host 'voyager' is known and matches the host key.
saturn.maki.dom: Encryption type: DES3
saturn.maki.dom: Sent encrypted session key.
saturn.maki.dom: Received encryption confirmation.
saturn.maki.dom: RSA authentication failed: Can't load public key.
saturn.maki.dom: Doing challenge response authentication.
saturn.maki.dom: No challenge presented.
saturn.maki.dom: Trying password authentication.
saturn.maki.dom: Sending command: passwd
saturn.maki.dom: Entering interactive session.
match 1
I am assuming we are still talking about the snippet you posted earlier:
Question: Which one of the following lines causes the behavior you are
seeing?
I would either use the debugger or insert some good old fashioned print
statements after each of the lines above to check that.
I went ahead and installed everything involved on the FreeBSD system I have
access to and tested the remoteinteract.pl script on my shell account with
my hosting provider. The remote password was successfully changed.
Here is the script as I tested it:
asu1@xxx:~ > perl -v
This is perl, v5.8.5 built for i386-freebsd-64int
asu1@xxx:~ > cat remoteinteract.pl
#!/usr/bin/perl
use constant HOST => 'example.com';
use constant USER => 'dummy';
use constant NEWPASS => 'newpass';
use constant OLDPASS => 'oldpass';
use strict;
use warnings;
use Net::SSH:
erl;
use Net::SSH:
erl::Constants qw( :msg );
my $ssh = Net::SSH:
erl->new(HOST, debug => 1);
$ssh->login(USER, OLDPASS);
$ssh->register_handler(SSH_SMSG_STDERR_DATA, sub {
my($ssh, $packet) = @_;
my $str = $packet->get_str;
if ($str =~ /^\(current\) UNIX password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(OLDPASS);
$packet->send;
}
elsif ($str =~ /^New password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}
elsif ($str =~ /^Retype new password:/) {
print ">>> $str\n";
my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA);
$packet->put_str(NEWPASS);
$packet->send;
}
});
$ssh->cmd('passwd');
__END__
asu1@xxx:~ > perl remoteinteract.pl
xxx.xxx.xxx.xxx: Reading configuration data /home/asu1/.ssh/config
xxx.xxx.xxx.xxx: Reading configuration data /etc/ssh_config
xxx.xxx.xxx.xxx: Connecting to example.com, port 22.
xxx.xxx.xxx.xxx: Remote protocol version 1.99, remote software version
OpenSSH_3.1p1
xxx.xxx.xxx.xxx: Net::SSH:
erl Version 1.23, protocol version 1.5.
xxx.xxx.xxx.xxx: No compat match: OpenSSH_3.1p1.
xxx.xxx.xxx.xxx: Connection established.
xxx.xxx.xxx.xxx: Waiting for server public key.
xxx.xxx.xxx.xxx: Received server public key (768 bits) and host key (1024
bits).
xxx.xxx.xxx.xxx: Host 'example.com' is known and matches the host key.
xxx.xxx.xxx.xxx: Encryption type: DES3
xxx.xxx.xxx.xxx: Sent encrypted session key.
xxx.xxx.xxx.xxx: Received encryption confirmation.
xxx.xxx.xxx.xxx: RSA authentication failed: Can't load public key.
xxx.xxx.xxx.xxx: Doing challenge response authentication.
xxx.xxx.xxx.xxx: No challenge presented.
xxx.xxx.xxx.xxx: Trying password authentication.
xxx.xxx.xxx.xxx: Sending command: passwd
xxx.xxx.xxx.xxx: Entering interactive session.