-hostkey problem

Advertisement

Hrki
Joined:
Posts:
2

-hostkey problem

Hello,

Batch code I am using: <invalid hyperlink removed by admin>

If i remove -hostkey XXX parameter script works like charm, but with -hostkey I don't get success. What am doing wrong? Would be better if I use winscp.com?

Reply with quote

Advertisement

m.w35tin
Guest

Try moving the " since hostkey is a parameter.

So instead of "-hostkey=ssh-ed25519 256 XXXXXXXXXXXXXXXXXXX="
Try -hostkey="ssh-ed25519 256 XXXXXXXXXXXXXXXXXXX="

Reply with quote

Hrki
Joined:
Posts:
2

It seems that only works with user who manual connect with WinSCP (GUI) and cache SSH data and then start batch code.

Job started in Task Scheduler as other user don't work :(

EDIT 2: Working solution is on bottom!

Full log (please keep attention on highlighted lines)
. 2018-03-15 07:29:00.002 WinSCP Version 5.13 (Build 8172) (OS 6.2.9200 - Windows Server 2012 Essentials)
. 2018-03-15 07:29:00.002 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2018-03-15 07:29:00.002 Log level: Normal
. 2018-03-15 07:29:00.002 Local account: server\user
. 2018-03-15 07:29:00.002 Working directory: C:\Program Files (x86)\WinSCP
. 2018-03-15 07:29:00.002 Process ID: 2204
. 2018-03-15 07:29:00.002 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe"  /log=D:\user\ftp.log /command "open sftp://user:***@192.168.0.2" "synchronize remote -resumesupport=on -criteria=time -filemask=*.rar|*/ D:\BACKUP\ /home/backup/" -hostkey="ssh-ed25519 256 XXXXXXXXXXXXXXXXXXXXXXXXXXXX" "exit"
. 2018-03-15 07:29:00.002 Time zone: Current: GMT+1, Standard: GMT+1 (Central European Standard Time), DST: GMT+2 (Central European Daylight Time), DST Start: 25.3.2018., DST End: 28.10.2018.
. 2018-03-15 07:29:00.002 Login time: 15. march 2018. 7:29:00
. 2018-03-15 07:29:00.002 --------------------------------------------------------------------------
. 2018-03-15 07:29:00.002 Script: Retrospectively logging previous script records:
< 2018-03-15 07:29:00.002 Script: Opening session using command-line parameter in scripting is deprecated. Use 'open' command instead.
. 2018-03-15 07:29:00.002 --------------------------------------------------------------------------
. 2018-03-15 07:29:00.002 Session name: exit (Ad-Hoc site)
. 2018-03-15 07:29:00.002 Host name: exit (Port: 22) (Host name: exit??)
. 2018-03-15 07:29:00.002 User name:  (Password: No, Key file: No, Passphrase: No)
. 2018-03-15 07:29:00.002 Tunnel: No
. 2018-03-15 07:29:00.002 Transfer Protocol: SFTP (SCP)
. 2018-03-15 07:29:00.002 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2018-03-15 07:29:00.002 Disable Nagle: No
. 2018-03-15 07:29:00.002 Proxy: None
. 2018-03-15 07:29:00.002 Send buffer: 262144
. 2018-03-15 07:29:00.002 SSH protocol version: 2; Compression: No
. 2018-03-15 07:29:00.002 Bypass authentication: No
. 2018-03-15 07:29:00.002 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2018-03-15 07:29:00.002 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2018-03-15 07:29:00.002 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2018-03-15 07:29:00.002 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2018-03-15 07:29:00.002 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2018-03-15 07:29:00.002 Simple channel: Yes
. 2018-03-15 07:29:00.002 Return code variable: Autodetect; Lookup user groups: Auto
. 2018-03-15 07:29:00.002 Shell: default
. 2018-03-15 07:29:00.002 EOL: LF, UTF: Auto
. 2018-03-15 07:29:00.002 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2018-03-15 07:29:00.002 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2018-03-15 07:29:00.002 SFTP Bugs: Auto,Auto
. 2018-03-15 07:29:00.002 SFTP Server: default
. 2018-03-15 07:29:00.002 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2018-03-15 07:29:00.002 Cache directory changes: Yes, Permanent: Yes
. 2018-03-15 07:29:00.002 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2018-03-15 07:29:00.002 DST mode: Unix
. 2018-03-15 07:29:00.002 --------------------------------------------------------------------------
. 2018-03-15 07:29:00.002 Looking up host "exit" for SSH connection (Host exit???)
. 2018-03-15 07:29:02.373 --------------------------------------------------------------------------
. 2018-03-15 07:29:02.373 WinSCP Version 5.13 (Build 8172) (OS 6.2.9200 - Windows Server 2012 Essentials)
. 2018-03-15 07:29:02.373 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2018-03-15 07:29:02.373 Log level: Normal
. 2018-03-15 07:29:02.373 Local account: server\user
. 2018-03-15 07:29:02.373 Working directory: C:\Program Files (x86)\WinSCP
. 2018-03-15 07:29:02.373 Process ID: 2204
. 2018-03-15 07:29:02.373 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe"  /log=D:\user\ftp.log /command "open sftp://user:***@192.168.0.2" "synchronize remote -resumesupport=on -criteria=time -filemask=*.rar|*/ D:\BACKUP\ /home/backup/" -hostkey="ssh-ed25519 256 XXXXXXXXXXXXXXXXXXXXXXXXXXXX" "exit"
. 2018-03-15 07:29:02.373 Time zone: Current: GMT+1, Standard: GMT+1 (Central European Standard Time), DST: GMT+2 (Central European Daylight Time), DST Start: 25.3.2018., DST End: 28.10.2018.
. 2018-03-15 07:29:02.373 Login time: 15. march 2018. 7:29:02
. 2018-03-15 07:29:02.373 --------------------------------------------------------------------------
. 2018-03-15 07:29:02.373 Script: Retrospectively logging previous script records:
< 2018-03-15 07:29:02.373 Script: Searching for host...
< 2018-03-15 07:29:02.373 Script: Host "exit" does not exist.
. 2018-03-15 07:29:02.373 Script: Failed
> 2018-03-15 07:29:02.373 Script: open sftp://user:***@192.168.0.2
. 2018-03-15 07:29:02.373 --------------------------------------------------------------------------
. 2018-03-15 07:29:02.373 Session name: user@192.168.0.2 (Ad-Hoc site)
. 2018-03-15 07:29:02.373 Host name: 192.168.0.2 (Port: 22)
. 2018-03-15 07:29:02.373 User name: user (Password: Yes, Key file: No, Passphrase: No)
. 2018-03-15 07:29:02.373 Tunnel: No
. 2018-03-15 07:29:02.373 Transfer Protocol: SFTP
. 2018-03-15 07:29:02.373 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2018-03-15 07:29:02.373 Disable Nagle: No
. 2018-03-15 07:29:02.373 Proxy: None
. 2018-03-15 07:29:02.373 Send buffer: 262144
. 2018-03-15 07:29:02.373 SSH protocol version: 2; Compression: No
. 2018-03-15 07:29:02.373 Bypass authentication: No
. 2018-03-15 07:29:02.373 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2018-03-15 07:29:02.373 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2018-03-15 07:29:02.373 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2018-03-15 07:29:02.373 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2018-03-15 07:29:02.373 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2018-03-15 07:29:02.373 Simple channel: Yes
. 2018-03-15 07:29:02.373 Return code variable: Autodetect; Lookup user groups: Auto
. 2018-03-15 07:29:02.373 Shell: default
. 2018-03-15 07:29:02.373 EOL: LF, UTF: Auto
. 2018-03-15 07:29:02.373 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2018-03-15 07:29:02.373 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2018-03-15 07:29:02.373 SFTP Bugs: Auto,Auto
. 2018-03-15 07:29:02.373 SFTP Server: default
. 2018-03-15 07:29:02.373 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2018-03-15 07:29:02.373 Cache directory changes: Yes, Permanent: Yes
. 2018-03-15 07:29:02.373 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2018-03-15 07:29:02.373 DST mode: Unix
. 2018-03-15 07:29:02.373 --------------------------------------------------------------------------
. 2018-03-15 07:29:02.373 Looking up host "192.168.0.2" for SSH connection
. 2018-03-15 07:29:02.373 Connecting to 192.168.0.2 port 22
. 2018-03-15 07:29:02.373 We claim version: SSH-2.0-WinSCP_release_5.13
. 2018-03-15 07:29:02.373 Server version: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
. 2018-03-15 07:29:02.373 Using SSH protocol version 2
. 2018-03-15 07:29:02.373 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2018-03-15 07:29:03.091 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2018-03-15 07:29:03.107 Host key fingerprint is:
. 2018-03-15 07:29:03.107 ssh-ed25519 256 XX:XX:XX XXXXXXXXXXXXXXXXXXXXXXXXXXXX
. 2018-03-15 07:29:03.107 Asking user:
. 2018-03-15 07:29:03.107 **Continue connecting to an unknown server and add its host key to a cache?**
. 2018-03-15 07:29:03.107 
. 2018-03-15 07:29:03.107 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.
. 2018-03-15 07:29:03.107 
. 2018-03-15 07:29:03.107 The server's Ed25519 key details are:
. 2018-03-15 07:29:03.107 
. 2018-03-15 07:29:03.107     Algorithm:   ssh-ed25519 256
. 2018-03-15 07:29:03.107     SHA-256:   XXXXXXXXXXXXXXXXXXXXXXXXXXXX
. 2018-03-15 07:29:03.107     MD5:   XX:XX:XX
. 2018-03-15 07:29:03.107 
. 2018-03-15 07:29:03.107 If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
. 2018-03-15 07:29:03.107 In scripting, you should use a -hostkey switch to configure the expected host key. () (But am using -hostkey switch...)
. 2018-03-15 07:29:13.138 Attempt to close connection due to fatal exception:
* 2018-03-15 07:29:13.138 Host key fingerprint is ssh-ed25519 256 XXXXXXXXXXXXXXXXXXXXXXXXXXXX.
* 2018-03-15 07:29:13.138 (Exception) **Host key wasn't verified!**
. 2018-03-15 07:29:13.138 Closing connection.
. 2018-03-15 07:29:13.138 Sending special code: 12

I managed to fix problem using winscp.com instead winscp.exe. Here is working code if someone has the same problems:

Backup.bat
SET WINSCP="C:\Program Files (x86)\WinSCP"
SET FTP_LOG=D:\Backup\ftp.log
PUSHD "%~dp0"
IF EXIST %FTP_LOG% DEL %FTP_LOG%
START /D %WINSCP% /B /WAIT WinSCP.com /log=%FTP_LOG% /ini=nul /script=D:\Backup\script.hrki
script.hrki
open sftp://user:pass@192.168.0.2 -hostkey="ssh-ed25519 256 XXXXX"
synchronize remote -resumesupport=on -criteria=time -filemask=*.rar|*/ D:\Backup /user/backup/
close
exit

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: -hostkey problem

This is not winscp.exe vs. winscp.com. It's /command vs. /script.

Anyway, with /command, the correct syntax is (both with winscp.exe and winscp.com):

/log=D:\user\ftp.log /command "open sftp://user:***@192.168.0.2 -hostkey=""ssh-ed25519 256 XXXXXXXXXXXXXXXXXXXXXXXXXXXX""" "synchronize remote -resumesupport=on -criteria=time -filemask=*.rar|*/ D:\BACKUP\ /home/backup/"exit"
See https://winscp.net/eng/docs/commandline#syntax

Next time, have WinSCP GUI generate the command-line syntax for you:
https://winscp.net/eng/docs/ui_generateurl#script

Reply with quote

Mathews
Guest

Why we need host key

Hi Team,

Much appreciated if someone can tell me why we need a hostkey in WinSCP scripting if we put username/password and server in the scripting file.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum