+1 vote
by (130 points)

Hi team,

I'm having problem connecting to SFTP using the library, but it connect fine with WinSCP. Below is the debugging log.

    2022-05-04 17:59:54.837 Opening log file.
2022-05-04 17:59:54.839 INFO FileLogWriter(1)[9] Info: Assembly: Rebex.Common 2018 R4 for .NET 4.0-4.7
2022-05-04 17:59:54.841 INFO FileLogWriter(1)[9] Info: Platform: Windows 10.0.19043 64-bit; CLR: 4.0.30319.42000
2022-05-04 17:59:54.841 DEBUG FileLogWriter(1)[9] Info: Culture: en; Windows-1252
2022-05-04 17:59:55.434 DEBUG Sftp(1)[9] SSH: Allowed authentication methods for 'xxxxxxxxx': publickey, password.
2022-05-04 17:59:55.434 DEBUG Sftp(1)[9] SSH: Trying public key authentication for 'xxxxxxxxx''.
2022-05-04 17:59:55.461 ERROR Sftp(1)[9] SSH: Rebex.Net.SshException: A public key corresponding to the supplied private key was not accepted by the server or the user name is incorrect.
   at Rebex.Net.SshSession.tsss(String agy, String agz, SshPrivateKey aha, SshGssApiCredentials ahb, Boolean ahc)
2022-05-04 17:59:59.476 ERROR Sftp(1)[9] Info: System.InvalidOperationException: Not authenticated to the server.
   at Rebex.Net.Sftp.nqxt()
   at Rebex.Net.Sftp.nqzv(String uf, Boolean ug, Boolean uh, Boolean ui, kuvq uj)

I also sent out WinSCP log to support@rebex.net.

Thanks.

1 Answer

0 votes
by (134k points)

When Rebex SFTP triggers the "A public key corresponding to the supplied private key was not accepted by the server or the user name is incorrect" exception, a wrong username or public key is almost always the cause. Other possible causes include temporary authentication outage at the server (unlikely if this is happening persistently) or some kind of incompatibility (possible but rare).

To address the problem, try following these steps:

  1. Double-check once more that you are in fact connecting to the same server, same port, using the same username and the same key.

  2. If no misconfiguration is discovered, see if it’s possible to check out the server log to see why it is rejecting the authentication attempt.

  3. If this is not possible or doesn’t reveal any clues, try announcing the public key to the server before attempting authentication:
    sftp.Settings.EnsureKeyAcceptable = true;

  4. If that doesn't help either, try enable signature padding to rule out the possibility that the server suffers from a padding bug in RSA signature validation:
    sftp.Settings.EnableSignaturePadding = true;
    // ^ if this doesn’t help, make sure to remove it

  5. Try using the latest version of Rebex SFTP.

  6. If nothing of the above helps, create a verbose communication log in both WinSCP and Rebex SFTP. This will reveal the difference in the way the two clients are authenticating. It's also the only way to make sure that the same key is actually being used in both applications.

by (130 points)
Thank you very much for your quick response and detailed suggestion. It turns out to be a careless mistake relates to letter case.
by (134k points)
Thanks for letting us know!
...