StrictHostKeyChecking with Net::SSH::Any

Specifying SSH options with Net::SSH::Any was not obvious. Here’s how to do it:

my $ssh = Net::SSH::Any->new(
      $self->ip_address,
      user => $user,
      key_path => $key,
      backends => ['Net::SSH2'],
      backend_opts => {
            'Net::SSH2' => {
                  options=> [
                        "StrictHostKeyChecking no",
                        "UserKnownHostsFile /dev/null",
                  ],
            },
      },
);

2 thoughts on “StrictHostKeyChecking with Net::SSH::Any”

  1. That’s wrong.

    The current stable version of Net::SSH2 doesn’t support checking the remote key, so, actually you never need to pass anything to disable strict host key checking.

    The development versions of Net::SSH::Any+Net::SSH2+libssh2 does support it. In that case you can use:

    $ssh = Net::SSH::Any->new(…, strict_host_key_checking => 0, known_hosts_path => ‘/dev/null’);
    </pre

    1. HI Salva,

      thanks for the tip. I was sure I needed these settings, but maybe that was with a previous SSH module.

      I think the post is still useful as a guide for passing options to the backend module, even if they are ignored!

Leave a Reply

Your email address will not be published. Required fields are marked *