Solved: Authentication failed from PowerShell, but works from GUI, WinSCP 6.1.2

Advertisement

MiiChiel
Joined:
Posts:
2
Location:
Europe

Solved: Authentication failed from PowerShell, but works from GUI, WinSCP 6.1.2

I'm using WinSCP 6.1.2, connecting to an sftp server by GUI works fine. Yet with PowerShell it does not work.

For my setup I have one SFTP server, with two usernames, first one works with GUI and PowerShell, second only works with GUI. I have read other topics that there was this bug in the older versions of WinSCP, is this still a thing? (Issue 388 – Ignore empty SSH keyboard interactive prompts)

This is de code I use to connect through PowerShell, which doesn't work with the second username, but does with the first. I have removed all critical information from the script and loggings.

try
{
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::sftp
        HostName = "sftpadress.com"
        UserName = "username"
        Password = "password"
        SshHostKeyFingerprint = "ssh-ed25519 255 hidden"
    }
 
    $session = New-Object WinSCP.Session
    $session.SessionLogPath = "d:\path\WinSCP_PowerShell\winscp.log"
    try
    { 
        # Connect
        $session.Open($sessionOptions)
 
        # Synchronize files
        $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, "E:\path1","/path1", $False)
        $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local, "E:\path2","/path2", $True)
 
        # Throw on any error
        #$synchronizationResult.Check()
 
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    #exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    #exit 1
}

This is the logging:
. 2023-10-02 11:10:49.404 --------------------------------------------------------------------------
. 2023-10-02 11:10:49.404 WinSCP Versie 6.1.2 (Build 13797 2023-09-19) (OS 10.0.20348 – Windows Server 2022 Standard)
. 2023-10-02 11:10:49.404 Configuration: nul
. 2023-10-02 11:10:49.404 Log level: Normal
. 2023-10-02 11:10:49.404 Local account: DOMEIN\Administrator
. 2023-10-02 11:10:49.404 Working directory: C:\Users\Administrator\AppData\Local\Programs\WinSCP
. 2023-10-02 11:10:49.404 Process ID: 10592
. 2023-10-02 11:10:49.420 Ancestor processes: powershell_ise, explorer, svchost, ...
. 2023-10-02 11:10:49.420 Command-line: "C:\Users\Administrator\AppData\Local\Programs\WinSCP\winscp.exe" /xmllog="C:\Users\Administrator\AppData\Local\Temp\wscp0574.032585EC.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /stdout /stdin /dotnet=6.1.2  /ini=nul /log="d:\bat\WinSCP_PowerShell\winscp.log"  /console /consoleinstance=_1396_48193514_395
. 2023-10-02 11:10:49.420 Time zone: Current: GMT+2, Standard: GMT+1 (West-Europa (standaardtijd)), DST: GMT+2 (West-Europa (zomertijd)), DST Start: 26-3-2023, DST End: 29-10-2023
. 2023-10-02 11:10:49.420 Login time: maandag 2 oktober 2023 11:10:49
. 2023-10-02 11:10:49.420 --------------------------------------------------------------------------
. 2023-10-02 11:10:49.420 Script: Retrospectively logging previous script records:
> 2023-10-02 11:10:49.420 Script: option batch on
< 2023-10-02 11:10:49.420 Script: batch           on        
< 2023-10-02 11:10:49.420 Script: reconnecttime   120       
> 2023-10-02 11:10:49.420 Script: option confirm off
< 2023-10-02 11:10:49.420 Script: confirm         off       
> 2023-10-02 11:10:49.420 Script: option reconnecttime 120
< 2023-10-02 11:10:49.420 Script: reconnecttime   120       
> 2023-10-02 11:10:49.420 Script: open sftp://username:***@sftpadress.com -hostkey="ssh-ed25519 255 hidden" -timeout=15
. 2023-10-02 11:10:49.420 --------------------------------------------------------------------------
. 2023-10-02 11:10:49.420 Session name: username:***@sftpadress.com (Ad-Hoc site)
. 2023-10-02 11:10:49.420 Host name: sftpadress.com (Port: 22)
. 2023-10-02 11:10:49.420 User name: username (Password: Yes, Key file: No, Passphrase: No)
. 2023-10-02 11:10:49.420 Tunnel: No
. 2023-10-02 11:10:49.420 Transfer Protocol: SFTP
. 2023-10-02 11:10:49.420 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2023-10-02 11:10:49.420 Disable Nagle: No
. 2023-10-02 11:10:49.420 Proxy: None
. 2023-10-02 11:10:49.420 Send buffer: 262144
. 2023-10-02 11:10:49.420 Compression: No
. 2023-10-02 11:10:49.420 Bypass authentication: No
. 2023-10-02 11:10:49.420 Try agent: Yes; Agent forwarding: No; KI: Yes; GSSAPI: Yes
. 2023-10-02 11:10:49.420 GSSAPI: KEX: No; Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2023-10-02 11:10:49.420 Ciphers: aes,chacha20,aesgcm,3des,WARN,des,blowfish,arcfour; Ssh2DES: No
. 2023-10-02 11:10:49.420 KEX: ntru-curve25519,ecdh,dh-gex-sha1,dh-group18-sha512,dh-group17-sha512,dh-group16-sha512,dh-group15-sha512,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2023-10-02 11:10:49.420 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2023-10-02 11:10:49.420 Simple channel: Yes
. 2023-10-02 11:10:49.420 Return code variable: Autodetect; Lookup user groups: Auto
. 2023-10-02 11:10:49.420 Shell: default
. 2023-10-02 11:10:49.420 EOL: LF, UTF: Auto
. 2023-10-02 11:10:49.420 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2023-10-02 11:10:49.420 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2023-10-02 11:10:49.420 SFTP Bugs: Auto,Auto
. 2023-10-02 11:10:49.420 SFTP Server: default
. 2023-10-02 11:10:49.420 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2023-10-02 11:10:49.420 Cache directory changes: Yes, Permanent: Yes
. 2023-10-02 11:10:49.420 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2023-10-02 11:10:49.420 DST mode: Unix
. 2023-10-02 11:10:49.420 --------------------------------------------------------------------------
< 2023-10-02 11:10:49.420 Script: Bezig met zoeken naar doelcomputer...
. 2023-10-02 11:10:49.420 Looking up host "sftpadress.com" for SSH connection
. 2023-10-02 11:10:49.420 Connecting to 0.0.0.0 port 22
. 2023-10-02 11:10:49.435 Connected to 0.0.0.0
< 2023-10-02 11:10:49.435 Script: Bezig met verbinding maken met doelcomputer...
. 2023-10-02 11:10:49.435 We claim version: SSH-2.0-WinSCP_release_6.1.2
. 2023-10-02 11:10:49.435 Connected to 0.0.0.0
. 2023-10-02 11:10:49.467 Remote version: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.9
. 2023-10-02 11:10:49.467 Using SSH protocol version 2
. 2023-10-02 11:10:49.467 Have a known host key of type ssh-ed25519
. 2023-10-02 11:10:49.482 Doing ECDH key exchange with curve Curve25519, using hash SHA-256
. 2023-10-02 11:10:49.576 Server also has ecdsa-sha2-nistp256/rsa-sha2-512/rsa-sha2-256/ssh-rsa host keys, but we don't know any of them
. 2023-10-02 11:10:49.576 Host key fingerprint is:
. 2023-10-02 11:10:49.576 ssh-ed25519 255 hidden
< 2023-10-02 11:10:49.576 Script: Bezig met authenticatie...
. 2023-10-02 11:10:49.576 Host key matches configured key fingerprint
. 2023-10-02 11:10:49.576 Initialised AES-256 SDCTR (AES-NI accelerated) [aes256-ctr] outbound encryption
. 2023-10-02 11:10:49.576 Initialised HMAC-SHA-256 outbound MAC algorithm
. 2023-10-02 11:10:49.576 Initialised AES-256 SDCTR (AES-NI accelerated) [aes256-ctr] inbound encryption
. 2023-10-02 11:10:49.576 Initialised HMAC-SHA-256 inbound MAC algorithm
! 2023-10-02 11:10:49.592 Using username "username".
< 2023-10-02 11:10:49.592 Script: Met gebruikersnaam "username".
. 2023-10-02 11:10:49.607 Server offered these authentication methods: publickey,password
. 2023-10-02 11:10:49.607 Prompt (password, "SSH password", <no instructions>, "&Wachtwoord: ")
. 2023-10-02 11:10:49.607 Using stored password.
< 2023-10-02 11:10:49.607 Script: Authenticatie met vooraf ingevoerd wachtwoord.
. 2023-10-02 11:10:49.607 Sent password
. 2023-10-02 11:10:52.185 Password authentication failed
! 2023-10-02 11:10:52.185 Access denied
< 2023-10-02 11:10:52.185 Script: Toegang geweigerd.
. 2023-10-02 11:10:52.185 Server offered these authentication methods: publickey,password
. 2023-10-02 11:10:52.185 Prompt (password, "SSH password", <no instructions>, "&Wachtwoord: ")
. 2023-10-02 11:10:52.185 Prompting user for the credentials.
. 2023-10-02 11:10:52.185 Prompt cancelled.
. 2023-10-02 11:10:52.185 User aborted at password prompt
. 2023-10-02 11:10:52.185 Attempt to close connection due to fatal exception:
* 2023-10-02 11:10:52.185 **Verbinding is onverwacht verbroken.** Server stuurde de opdrachtbeëindigingsstatus 0.
. 2023-10-02 11:10:52.185 Closing connection.
< 2023-10-02 11:10:52.201 Script: Verbinding is onverwacht verbroken. Server stuurde de opdrachtbeëindigingsstatus 0.
< 2023-10-02 11:10:52.201 Authenticatielogboek (bekijk het sessielogboek voor meer gegevens):
< 2023-10-02 11:10:52.201 Met gebruikersnaam "username".
< 2023-10-02 11:10:52.201 Toegang geweigerd.
< 2023-10-02 11:10:52.201 
 
< 2023-10-02 11:10:52.201 Authenticatie mislukt.

So of course the question is: what is going wrong?
Last edited by MiiChiel on 2023-10-02 11:27; edited 1 time in total

Reply with quote

Advertisement

MiiChiel

Solved

I got it solved: I had to use the password with singlequotes to prevent characters being escaped.

Because there are some special characters I didn't recognize that they were being escaped in the first place, that makes sense.

Reply with quote

Advertisement

You can post new topics in this forum