http://www.perlmonks.org?node_id=1004747


in reply to Capturing SSH output in an array.

Hi Salva,

The script works fine if I include the username and password, but fails when I use the key_path => "/home/$user/.ssh/id_dsa"); option.

Here's the script:

#!/usr/bin/perl use Modern::Perl; use Net::SSH::Any; my $hostname = '192.168.247.128'; my $username = 'perl514'; my $password = 'redhat'; say "Trying to connect to $hostname . Might take a while"; my $ssh = Net::SSH::Any->new($hostname, user => $username, key_path => + "/home/$username/.ssh/id_dsa"); if ($ssh->error) { say "whee...something wrong here: " . $ssh->error; } else { say " I am connected to $hostname!!!"; my @out = $ssh->capture("ls -la"); say "The files and directories of $username on $hostname are given + below"; say "@out"; }

And here is the error message

perl anytest1.pl Trying to connect to 192.168.247.128 . Might take a while whee...something wrong here: Authentication failed

This is slightly modified version of your script and I am running this on my office laptop that has Windows 7 installed with DWIM Perl. The script is pointing to CentOS 6.2 running as Guest OS inside of VMWare Player. I am able to ping to it as well as putty into it, so no issues there.I thought that there could be issues with the way  $username is being interpolated, but that's not the issue. The /home/$user/.ssh/id_dsa refers to id_dsa inside the CentOS 6.2. I am able to login to the Guest OS using the same username and password mentioned in the script, so any issues due wrong username and password are ruled out as well.

So I tried similar stuff using the  Net::SSH2 module, because from what I understand,  Net::SSH::Any module would use either  Net::OpenSSH or  Net::SSH2 in the backend. tried with  Net::SSH2 and same error was observed. Not sure where I am going wrong. Please help me.

Perlpetually Indebted To PerlMonks