Hi everyone, I've got a problem with key authentication using Net::OpenSSH. The problem is I have read the documentation and simply I couldn't find anything about it there. I tried to do it in normal way, as with ssh so I created a pair of keys, copied public to the remote server, tried login from CLI, worked. When did it from script it says "unable to establish master SSH connection: ssh master exited unexpectedly".
$ENV{HOME} = "/var/www/scripts/new"; use Net::OpenSSH; use Date::Simple ('date', 'today'); use warnings; my $ssh; $ssh = Net::OpenSSH->new('root@localhost', master_opts => [-o => "User +KnownHostsFile=/dev/null", -o => "StrictHostKeyChecking=no"], timeout + => 10, ctl_dir => $ENV{HOME}) or $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error +; my $cmd = "ls -l"; my (@out, $err) = $ssh->capture({ timeout => 10 }, $cmd); $ssh->error; print $ssh->error; foreach (@out) { print $out[$i]. "<BR>"; $i++; }
Obviously when I put the password in it works. It also works from the command line. Directory /var/www/scripts/new contains .ssh/ directory with id_rsa and id_rsa.pub now even with 777 to avoid a mistake in user rights. I'm running that script from other .cgi by system function. And also here when I put password everything works. Thank you for your all answers. Regards, Jarek

In reply to Net::OpenSSH key authentication by Jarek

Title:
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, details, 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, summary, 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.