Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Capturing SSH output in an array. by perl514
in thread Capturing SSH output in an array. by perl514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found