3

I'm writing a Perl script to SSH into remote linux and maci machines from a windows. For that I'm running plink (putty link) command using qx. The problem is that when I try to run the plink command it gives a prompt

The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. ...... If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n)

I have to automate the process of running a command remotely. So, I somehow want to bypass this warning.

I could think of two ways of doing this but don't know how to accomplish these

  • Somehow bypass this warning from putty itself through some command line options or other commands
  • Some Perl way of passing input to plink when prompted

Can anyone suggest how to do this either in one of above ways or some other solutions.

him
  • 487
  • 3
  • 12

1 Answers1

1

I solved it using pipes to pass Y to plink when prompted - echo Y | plink -ssh <user>@<host> -pw <password> <command>.

For more details refer to this answer. Also note the answer by @clay where he says

For internal servers, the blind echo y | ... trick is probably adequate (and super simple). However, for external servers accessed over the internet, it is much more secure to accept the server host key once rather than blindly accepting every time.

This was the case with me - I was using plink to ssh to internal servers.

him
  • 487
  • 3
  • 12
  • So please do not post duplicate answers. Close your question as a duplicate. – Martin Prikryl Jul 01 '19 at 06:35
  • Well this is a workaround I found for my problem. But as I said there might be more Perl(ish) way of doing this thing which I don't know. Using `Expect` is one such way as suggested by @zdim - but I thought it was not compatible with windows. – him Jul 01 '19 at 07:42
  • Well, the more Perlish way is to use a native Perl implementation of SSH, not Plink. – Martin Prikryl Jul 01 '19 at 07:53