Search code examples
sshmd5sftpwinscp

WinSCP Command line - Adding known hosts


I have windows batch script which connect to a server for fetching the transaction files.

The program uses Winscp command line scripting to open sftp connection and fetch the required files.

Recently the provider asked to update the known hosts and provided fingerprints in MD5,SHA 256, Bubble Babble options. I would like to continue executing the program in passive mode without any manual intervention on prompts.

With my limited knowledge in this, I understand adding an additional parameter with -hostkey will solve the issue. But I'm not not whether I need to add any additional parameter to specify whether it is MD5 or SHA etc. Any help is appreciated.

Current code:

open sftp://%USERNAME%@%HOSTNAME% 

Planning to update to

open sftp://%USERNAME%@%HOSTNAME% -hostkey="<key>"

Solution

  • You do not specify the fingerprint algorithm. Just specify the fingerprint using one of the format that WinSCP understands.

    The -hostkey switch supports two formats:

    • MD5: keytype bits fi:ng:er:pr:in:t
    • SHA-256: keytype bits fingerprint=

    For example:

    • ssh-dss 2048 0b:77:8b:68:f4:45:b1:3c:87:ad:5c:be:3b:c5:72:78
    • ssh-ed25519 256 D+O+VGvZhUStHQL82ph5ogOWnP7Dvn+XsFie47+1Jr0=

    SHA-256 is supported by recent versions of WinSCP only.