I have a ~/.ssh/known_hosts file which stores all my ssh keys for all aps.

Recently I started using the Net::SSH and SFTP Perl modules, and they created and used a new file known_hosts2. Is there a way I can force them to use the existing file, and not add a new one? I need to connect to nodes in the known_hosts file but these modules seem to ignore it.

Remarkably even if I explicitly TELL it what hostfile to use, it ignores that and uses known_hosts2:

my $keyfile='~/.ssh/known_hosts'; Net::SSH::Perl->new( $host, [identity_files => [$keyfile]);
..which seems to be 100% disregarded. I examined the ssh object and this doesn't appear in it at all after returning from login() (it is there after new()

I studied the metacpan page for SFTP; I don't see a way to specify to use the existing file in the new() args, so I'm not sure if this approach is even meaningful.

The known_hosts file has the default privs. According to chatbot AI, privs > 600 are acceptable. They are in fact 700.

Advice please? I don't want to fork this file (for now I cut the new keys from hosts2 and pasted them into hosts, and deleted hosts2.)

Rolf is this in your wheelhouse (hope so , your replies are ALWAYS amazingly helpful!)....

On a related note, I was in the debugger stepping through Net::SSH::Perl::AuthMgr and reached this line:

$code->($amgr, $packet, @args);
I've never seen a syntax like $object->(list) ; seems like the a method name is missing? IS there a default class method? This is the point where the connection errors..

- MP


In reply to Why does Net::SFTP and Net::SSH::Perl not use "known_hosts" by misterperl

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.