What is hostkey in WinSCP script?

Viewed 1429

I am trying to automate a backup process with WinSCP. I am trying to set up a WinSCP script, but I have troubles with the SSH authentication.

My very simple script is this:

# Connect to SFTP server using a password
open sftp://myusername:mypw@mywebspace.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx...="
# Upload file
put C:\pic.jpg /backup/
# Exit WinSCP
exit

The part I have troubles with is the -hostkey switch. I generated a key with PuTTYgen, and saved it on my webspace. Yet I don't know what to put into my script. Everything I try seems to get a "authentication failed" when running the script.

This is what I get in PuTTYgen: enter image description here

Which of this should I put in the script? What exactly does that look like?

I'm grateful for all helpful advice, as I a'm new to this.

1 Answers

The host key is a public key of your SSH server. It has nothing to do with the key pair you generate for authentication to the server. What goes to the -hostkey switch is a fingerprint of the server's public key – Just follow the switch documentation. You use it to verify the server identity to avoid MITM attacks.

See WinSCP FAQ Where do I get SSH host key fingerprint to authorize the server?.

As you seem to get to the authentication phase ("authentication failed"), your immediate problem is not the host key. The authentication happens only after verifying the host key. As you seem to put a wrong value to the -hostkey switch, yet the host key is verified – it means that you have the host key cached in registry anyway. If you have problem with authentication, please first make sure you can login to the SSH server anyhow (e.g. from WinSCP GUI). And only then try to automate the process.

See also Understanding SSH key pairs.

Related