I've spent quite a bit of time getting into coding with Net:SSH:Perl and have come across an interesting problem. The examples provided for that module suggest I can remotely change my password over SSH however neither example will work even after modifying it. Here is my sample ssh code:
#!/usr/bin/perl
use warnings;
use strict;
use Net::SSH::Perl;
my $srvr = "testserver";
my $username = "test";
my $oldpasswd = "test";
my ($stdout, $stderr, $exit);
my $cmd = ('passwd');
my $ssh = Net::SSH::Perl->new($srvr, protocol => 2, debug => 1);
$ssh->register_handler("stderr", sub {
my($channel, $buffer) = @_;
print "** Standard Error - I received this:\n", $buffe
+r->bytes;
});
# This trigger works perfectly
#
$ssh->register_handler("stdout", sub {
my($channel, $buffer) = @_;
print "** Standard Out - I received this:\n", $buffer-
+>bytes;
});
$ssh->login($username, $oldpasswd);
$ssh->cmd($cmd);
print "** Ran Command ". $cmd ."\n";
the code runs fine if I put a command such as 'ls' or 'hostname' (for example) in variable $cmd. If I put 'passwd' then the register_trigger for stderr comes back with the following error message
chqpvul8108: channel 1: new client-session
chqpvul8108: Requesting channel_open for channel 1.
chqpvul8108: Entering interactive session.
chqpvul8108: Sending command: passwd
chqpvul8108: Requesting service exec on channel 1.
chqpvul8108: channel 1: open confirm rwindow 0 rmax 16384
chqpvul8108: channel 1: rcvd eof
chqpvul8108: channel 1: output open -> drain
chqpvul8108: input_channel_request: rtype exit-status reply 0
chqpvul8108: channel 1: rcvd close
chqpvul8108: channel 1: input open -> closed
chqpvul8108: channel 1: close_read
** Standard Error - I received this:
Unexpected failure. Password file/table unchanged.
chqpvul8108: channel 1: obuf empty
chqpvul8108: channel 1: output drain -> closed
chqpvul8108: channel 1: close_write
chqpvul8108: channel 1: send close
chqpvul8108: channel 1: full closed
** Ran Command passwd
Any thoughts on what I'm missing here? I've googled and checked out the net::ssh::perl forum and haven't figured out why It's giving me heartburn. Has anyone been successful in issuing passwd with this module? This is running on a Suse Linux server and the client is a Solaris 9 Sparc. The reason I'm doing this is I'm writing a program to connect via SSH and change my password on a number of Unix/Linux servers (don't ask). Thanks!