server sent: publickey

Advertisement

sap
Joined:
Posts:
3
Location:
Moscow

server sent: publickey

1. At authorization through a script - everything works
winscp.exe /console /script="C:\WinSCPscript\script1.txt" /log="C:\WinSCPscript\script1.log"
open sftp://ubuntu@ec2-52-32-183-91.us-west-2.compute.amazonaws.com:22/ -privatekey=C:\WinSCPscript\ludm2.ppk
2. At authorization through Assembly - doesn't work
sessionOptions.Protocol = Protocol_Sftp;
sessionOptions.HostName = "ec2-52-32-183-91.us-west-2.compute.amazonaws.com";
sessionOptions.UserName = "ubuntu";
sessionOptions.SshPrivateKeyPath = "C:\WinSCPscript\ludm2.ppk";
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 2b:3f:51:0b:27:6d:7c:76:a4:a7:0b:3c:f4:f5:a1:c6";
C:\WinSCPauto>cscript script2.wsf
Error: Disconnected: No supported authentication methods available (server sent: publickey)
3. The field SshPrivateKeyPassphrase when transforming a PrivateKey to PuTTYgen left empty.

How it is correct to establish SessionOptions?

Reply with quote

Advertisement

sap
Joined:
Posts:
3
Location:
Moscow

Re: server sent: publickey

1. session log file for script:
. 2016-03-10 20:58:05.848 --------------------------------------------------------------------------
. 2016-03-10 20:58:05.848 WinSCP Version 5.7.6 (Build 5874) (OS 6.1.7601 Service Pack 1 - Windows 7 Home Basic)
. 2016-03-10 20:58:05.848 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2016-03-10 20:58:05.848 Log level: Normal, Logging passwords
. 2016-03-10 20:58:05.848 Local account: SAP\U
. 2016-03-10 20:58:05.848 Working directory: C:\Program Files\WinSCP
. 2016-03-10 20:58:05.848 Process ID: 4556
. 2016-03-10 20:58:05.848 Command-line: winscp.exe  /console /script="C:\WinSCPscript\script1.txt" /log="C:\WinSCPscript\script1.log" 
. 2016-03-10 20:58:05.848 Time zone: Current: GMT+3 (Калининградское время (зима)), No DST
. 2016-03-10 20:58:05.848 Login time: 10 Март 2016 г. 20:58:05
. 2016-03-10 20:58:05.848 --------------------------------------------------------------------------
. 2016-03-10 20:58:05.848 Script: Retrospectively logging previous script records:
> 2016-03-10 20:58:05.848 Script: open sftp://ubuntu@ec2-52-32-183-91.us-west-2.compute.amazonaws.com:22/ -privatekey=C:\WinSCPscript\ppk\ludm2.ppk
. 2016-03-10 20:58:05.848 --------------------------------------------------------------------------
. 2016-03-10 20:58:05.848 Session name: ubuntu@ec2-52-32-183-91.us-west-2.compute.amazonaws.com (Ad-Hoc site)
. 2016-03-10 20:58:05.848 Host name: ec2-52-32-183-91.us-west-2.compute.amazonaws.com (Port: 22)
. 2016-03-10 20:58:05.848 User name: ubuntu (Password: No, Key file: C:\WinSCPscript\ppk\ludm2.ppk)
. 2016-03-10 20:58:05.848 Tunnel: No
. 2016-03-10 20:58:05.848 Transfer Protocol: SFTP
. 2016-03-10 20:58:05.848 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2016-03-10 20:58:05.848 Disable Nagle: No
. 2016-03-10 20:58:05.848 Proxy: none
. 2016-03-10 20:58:05.848 Send buffer: 262144
. 2016-03-10 20:58:05.848 SSH protocol version: 2; Compression: No
. 2016-03-10 20:58:05.848 Bypass authentication: No
. 2016-03-10 20:58:05.848 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2016-03-10 20:58:05.848 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2016-03-10 20:58:05.848 KEX: dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN
. 2016-03-10 20:58:05.848 SSH Bugs: A,A,A,A,A,A,A,A,A,A,A,A
. 2016-03-10 20:58:05.848 Simple channel: Yes
. 2016-03-10 20:58:05.848 Return code variable: Autodetect; Lookup user groups: A
. 2016-03-10 20:58:05.848 Shell: default
. 2016-03-10 20:58:05.848 EOL: 0, UTF: 2
. 2016-03-10 20:58:05.848 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2016-03-10 20:58:05.848 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2016-03-10 20:58:05.848 SFTP Bugs: A,A
. 2016-03-10 20:58:05.848 SFTP Server: default
. 2016-03-10 20:58:05.848 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2016-03-10 20:58:05.848 Cache directory changes: Yes, Permanent: Yes
. 2016-03-10 20:58:05.848 DST mode: 1
. 2016-03-10 20:58:05.848 --------------------------------------------------------------------------
. 2016-03-10 20:58:05.848 Looking up host "ec2-52-32-183-91.us-west-2.compute.amazonaws.com"
. 2016-03-10 20:58:05.879 Connecting to 52.32.183.91 port 22
. 2016-03-10 20:58:06.379 Server version: SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
. 2016-03-10 20:58:06.379 Using SSH protocol version 2
. 2016-03-10 20:58:06.379 We claim version: SSH-2.0-WinSCP_release_5.7.6
. 2016-03-10 20:58:06.614 Doing Diffie-Hellman group exchange
. 2016-03-10 20:58:07.128 Doing Diffie-Hellman key exchange with hash SHA-256
. 2016-03-10 20:58:13.321 Verifying host key rsa2 0x10001,0xccc6df3d94c96247 27554a535171a5d3 8c16703bf8cd198f 57a7674c83483112 e995d03b99a31c16 4275beba1d438814 301352885c1c2f32 5fa74f181925ab25 8c8ccc548348570d 1744582492cd4416 7fc79f647a018576 a8f11a82d76a0059 11615558eca072ea 27aeeb983c5be3f3 57d46fbe9aa54e16 0ea4d88680e35bc5 37ae853cd8d04fc1 01c09549fcf5b269 3398789ea457386c ca32c1c0e6916ee5 929e57b5137cc0f5 223159d8d220ea0c ad6d039ce93e4748 712545b6b0768ae4 9f43bc24bade9418 af667c59c858b603 fbab187d3ec56c0f 5d9d15a9d100d497 f96156e64f213dd1 9b954c05df2ef33b 88947092b3493c64 36b40ec85391b4d5  with fingerprint ssh-rsa 2048 2b:3f:51:0b:27:6d:7c:76:a4:a7:0b:3c:f4:f5:a1:c6
. 2016-03-10 20:58:13.321 Host key matches cached key
. 2016-03-10 20:58:13.321 Host key fingerprint is:
. 2016-03-10 20:58:13.321 ssh-rsa 2048 2b:3f:51:0b:27:6d:7c:76:a4:a7:0b:3c:f4:f5:a1:c6
. 2016-03-10 20:58:13.337 Initialised AES-256 SDCTR client->server encryption
. 2016-03-10 20:58:13.337 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2016-03-10 20:58:13.337 Initialised AES-256 SDCTR server->client encryption
. 2016-03-10 20:58:13.337 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2016-03-10 20:58:13.867 Reading private key file "C:\WinSCPscript\ppk\ludm2.ppk"
! 2016-03-10 20:58:13.883 Using username "ubuntu".
. 2016-03-10 20:58:14.195 Offered public key
. 2016-03-10 20:58:14.444 Offer of public key accepted
! 2016-03-10 20:58:14.444 Authenticating with public key "imported-openssh-key"
. 2016-03-10 20:58:15.396 Sent public key signature
. 2016-03-10 20:58:15.645 Access granted
. 2016-03-10 20:58:15.645 Opening session as main channel
. 2016-03-10 20:58:23.201 Opened main channel
. 2016-03-10 20:58:23.685 Started a shell/command
. 2016-03-10 20:58:23.716 --------------------------------------------------------------------------
. 2016-03-10 20:58:23.747 Using SFTP protocol.
. 2016-03-10 20:58:23.747 Doing startup conversation with host.
> 2016-03-10 20:58:23.747 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2016-03-10 20:58:23.997 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2016-03-10 20:58:23.997 SFTP version 3 negotiated.
. 2016-03-10 20:58:23.997 Unknown server extension posix-rename@openssh.com="1"
. 2016-03-10 20:58:23.997 Supports statvfs@openssh.com extension version "2"
. 2016-03-10 20:58:23.997 Unknown server extension fstatvfs@openssh.com="2"
. 2016-03-10 20:58:23.997 Supports hardlink@openssh.com extension version "1"
. 2016-03-10 20:58:23.997 Unknown server extension fsync@openssh.com="1"
. 2016-03-10 20:58:23.997 We believe the server has signed timestamps bug
. 2016-03-10 20:58:23.997 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 string are not mandatory
. 2016-03-10 20:58:23.997 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2016-03-10 20:58:23.997 Getting current directory name.
. 2016-03-10 20:58:23.997 Getting real path for '.'
> 2016-03-10 20:58:23.997 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2016-03-10 20:58:24.231 Type: SSH_FXP_NAME, Size: 45, Number: 16
. 2016-03-10 20:58:24.231 Real path is '/home/ubuntu'
. 2016-03-10 20:58:24.231 Startup conversation with host finished.
< 2016-03-10 20:58:24.231 Script: Active session: [1] ubuntu@ec2-52-32-183-91.us-west-2.compute.amazonaws.com
> 2016-03-10 20:58:24.246 Script: cd /home/ubuntu/instanceDataJson
. 2016-03-10 20:58:24.293 Changing directory to "/home/ubuntu/instanceDataJson".
. 2016-03-10 20:58:24.293 Getting real path for '/home/ubuntu/instanceDataJson'
> 2016-03-10 20:58:24.293 Type: SSH_FXP_REALPATH, Size: 38, Number: 272
< 2016-03-10 20:58:24.527 Type: SSH_FXP_NAME, Size: 79, Number: 272
. 2016-03-10 20:58:24.527 Real path is '/home/ubuntu/instanceDataJson'
. 2016-03-10 20:58:24.527 Trying to open directory "/home/ubuntu/instanceDataJson".
> 2016-03-10 20:58:24.527 Type: SSH_FXP_LSTAT, Size: 38, Number: 519
< 2016-03-10 20:58:24.761 Type: SSH_FXP_ATTRS, Size: 37, Number: 519
. 2016-03-10 20:58:24.792 Getting current directory name.
< 2016-03-10 20:58:24.792 Script: /home/ubuntu/instanceDataJson
> 2016-03-10 20:58:24.839 Script: close
. 2016-03-10 20:58:24.839 Closing connection.
. 2016-03-10 20:58:24.839 Sending special code: 12
. 2016-03-10 20:58:24.839 Sent EOF message
2. session log file for assembly can't get at WinSCP.
What logs are interested in and how to get them?

2.1. script2.wsf
<job>
<reference object="WinSCP.Session" />
<script language="JScript">
 
try
{
    // Setup session options
    var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions");
    sessionOptions.Protocol = Protocol_Sftp;
    sessionOptions.HostName = "ec2-52-32-183-91.us-west-2.compute.amazonaws.com";
    sessionOptions.UserName = "ubuntu";
    sessionOptions.SshPrivateKeyPath = "C:\WinSCPauto\ludm2.ppk";
   sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 2b:3f:51:0b:27:6d:7c:76:a4:a7:0b:3c:f4:f5:a1:c6";
   //sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = "yes";
   //sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 f2:f9:60:f4:0e:f5:67:74:d2:77:c4:7b:39:ba:51:d7";
   //sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 27:c0:3e:7c:d9:4d:7b:15:65:e4:cc:8c:4e:d0:9d:94";
   //sessionOptions.SshHostKeyFingerprint = "null";
   //sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 fd:6a:74:c0:55:30:cd:01:11:0b:2f:ba:f0:d1:d7:ab";
   //sessionOptions.SshPrivateKeyPassphrase = "kontora";
   //sessionOptions.SshPrivateKeyPassphrase = "soecon";
    var session = WScript.CreateObject("WinSCP.Session");
 
    try
    {
        // Connect
       session.Open(sessionOptions);
2.2.
C:\WinSCPauto>cscript script2.wsf
Сервер сценариев Windows (Microsoft R) версия 5.8
c Корпорация Майкрософт (Microsoft Corp.), 1996-2001. Все права защищены.

Error: Disconnected: No supported authentication methods available (server sent: publickey)

C:\WinSCPauto>

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: server sent: publickey

I guess the problem is, that you do not escape the backslashes in the path to the private key file:
sessionOptions.SshPrivateKeyPath = "C:\\WinSCPauto\\ludm2.ppk";
If this does not help, set session.SessionLogPath before calling session.Open.

Reply with quote

Advertisement

You can post new topics in this forum