Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #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 = ''; 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 Trying to connect to . 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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [marto]: your account is 7 days old, how old are these 'old tgimers'?
    [choroba]: usemodpoerl Do you have a question? Do you want to help someone? Or do you just want to troll?
    [usemodperl]: perlmonks used to be a safe space for perl coders, now it's like having an annoying girlfriend...
    [marto]: I had a feeling I'd regret looking up the definition of 'soyboy'
    [Veltro]: usemodperl Maybe it is the way you talk? 'Soy boys', 'old ladies' and what is even a tgimer...
    usemodperl is venting, duh?
    [usemodperl]: that was a typos, dumbass
    [marto]: usemodperl I guess that depends on what you mean by a safe space, since many people seem to have the impression a safe space allows them to do/say whatever they feel like, without question or critque
    [marto]: 'typos'->'typo'
    [usemodperl]: it's like you guys are retarded or something, no sense of humor? autism?

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (10)
    As of 2018-06-24 15:46 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.