vasanth.easyrider has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks
I have a requirement where i need to connect to 1000 devices using SSH. But we all know that when we do SSH for the first time, we get the following prompt =

The authenticity of host '10.3.170.37 (10.3.170.37)' can't be established. ECDSA key fingerprint is 4f:2e:c4:f1:d7:f6:9a:07:c5:62:17:00:0d:1d:77:26. Are you sure you want to continue connecting (yes/no)?

because of this prompt, i am not able to use Net::SSH module to fulfill my requirements. Can you help me on how to deal with the above prompt for the first time when we attempt to connect to the device?

Will Expect module fulfill my requirement?

Replies are listed 'Best First'.
Re: SSH - Key Authentication
by hippo (Archbishop) on Apr 06, 2018 at 08:22 UTC
    Can you help me on how to deal with the above prompt for the first time when we attempt to connect to the device?

    The easy solution is to set strict_host_key_checking => 0 in the Net::SSH::Any constructor. This is of course very insecure but since your previous posts on the subject suggest that security is a very low priority for you then this may be sufficient.

      i already tried strict_host_key_checking => 0 in the past, for few devices SSH connection was not happening. i was getting error message that "channel not identified". This was because of using the option strict_host_key_checking => 0. Hence i decided not to use it

        Those are unrelated things. You were probably doing something else wrong.
Re: SSH - Key Authentication
by afoken (Chancellor) on Apr 06, 2018 at 11:40 UTC

    But we all know that when we do SSH for the first time, we get the following prompt =

    The authenticity of host '10.3.170.37 (10.3.170.37)' can't be established. ECDSA key fingerprint is 4f:2e:c4:f1:d7:f6:9a:07:c5:62:17:00:0d:1d:77:26. Are you sure you want to continue connecting (yes/no)?

    Connect once manually, and the prompt will disappear. ssh stores the remote host's key in $HOME/.ssh/known_hosts when you first connect to a remote host. This is a quite simple file, using one line per host. You could also copy lines from one system to another to get rid of the prompt. There is also a system-wide known_hosts file /etc/ssh/ssh_known_hosts. See also https://en.wikibooks.org/wiki/OpenSSH/Client_Configuration_Files.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      You advice of
      Connect once manually
      vs the requirement of
      connect to 1000 devices
      could be a problem...
Re: SSH - Key Authentication
by marto (Cardinal) on Apr 06, 2018 at 09:21 UTC
Re: SSH - Key Authentication
by thanos1983 (Parson) on Apr 06, 2018 at 08:21 UTC

    Hello vasanth.easyrider,

    I have never tried it for new ssh sessions but it should work. Try to use Expect.

    Pseudo code bellow:

    #!/usr/bin/perl use Expect; use strict; use warnings; # create an Expect object by spawning another process my $exp = Expect->spawn($command, @params); $exp->send("yes");

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!