4

I am trying to connect to Unix server from WinSCP commandline for the first time.

It closes with the the following error:

The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is.

The server's rsa2 key fingerprint is: ssh-rsa 1024 42:9e:c7:f4:7f:8b:50:10:6a:06:04:b1:d4:f2:04:6d If you trust this host, press Yes. To connect without adding host key to the cac he, press No. To abandon the connection press Cancel.

In the WinSCP commandline, it does not ask for any input (Yes or No). It closes with Authentication failed. If I connect through the WinSCP tool, I'll get the same error. However, I'll be able to press YES.

I also know that If I add -hostkey switch in the command line, I'll be able to connect. But, I don't want pass hostkey in my batch script as I will be connecting to various servers. So, my requirement is to pass "YES" input from the commandline in case of this error. Can someone help?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ekata Bavkar
  • 83
  • 2
  • 9

1 Answers1

1

A host key fingerprint verification is a crucial step in securing your SSH connection. Even if you are using a set of sessions with your script, it does not excuse you. The fingerprint should be part of a set of information you have for each of the sessions (in addition to a hostname, an username and a password).

Skipping the fingerprint verification means that you lose any security and there's no point using an SSH/SFTP anymore.

Anyway, if you do not care about a security, you can use the -hostkey=* switch to unconditionally accept any host key.

Further references:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • hi @Martin, this is not working for me. call C:\Progra~2\WinSCP\WinSCP.exe /console -timeout="120" /command "option batch continue" "option confirm off" "open sftp://%userin%:%pasw%@host -hostkey="*"" "get /home/*.*" – Ekata Bavkar Sep 05 '14 at 18:54
  • Your command conflicts with Markdown syntax, so I cannot see it literally. But I assume that original was `"open sftp://%userin%:%pasw%@host -hostkey="*""`. That's wrong, either use `"open sftp://%userin%:%pasw%@host -hostkey=""*"""` or avoid quotes around `*`: `"open sftp://%userin%:%pasw%@host -hostkey=*"` See [command-line syntax](http://winscp.net/eng/docs/commandline#syntax). – Martin Prikryl Sep 05 '14 at 19:00
  • Also `-timeout="120"` specified as command-line parameter does not apply to session opened using scripting commands. You have to combine it with `open` command: `"open sftp://%userin%:%pasw%@host -hostkey=* -timeout=120"` – Martin Prikryl Sep 05 '14 at 19:03