0 votes
by (280 points)

SshPrivateKey privateKey = null;
privateKey = new SshPrivateKey(ppkFilename, password);
var sftp = new Sftp();
sftp.Connect(hostName);
ftp.Login(username, privateKey); //Here I am getting error.

Applies to: Rebex SFTP

1 Answer

+1 vote
by (75.8k points)
selected by
 
Best answer

<add key="userPublicKeyDir" value="keys"/>

var pk = SshPrivateKey.Generate();
pk.Save("user1.pri", "password", SshPrivateKeyFormat.OpenSsh);
pk.SavePublicKey("user1.pub", SshPublicKeyFormat.Ssh2Base64);

by (280 points)
I followed same steps but still I am getting same error. I am able login with ftp.Login(username, password, privateKey) and
ftp.Login(username, password);
but still not  able to login with

ftp.Login(username, privateKey);

Please help
by (75.8k points)
Do you see "Public key authentication enabled." message in server's log?
If not, you configure the server incorrectly.

If yes, and it is still not working, please post here debug log. It can be produced like this:

using (var sftp = new Sftp())
{
    sftp.LogWriter = new FileLogWriter(@"c:\data\sftp.log", LogLevel.Debug);               
    sftp.Connect("localhost", 22);
    sftp.Login("tester", new SshPrivateKey(@"c:\data\user1.pri", "password"));
}
by (280 points)
Hi Lukas,

I didn't get "Public key authentication enabled." message. Please find the logs,

2017-06-05 01:06:05.225 Opening log file.
2017-06-05 01:06:05.225 Using FileLogWriter version 2.0.5584.0.
2017-06-05 01:06:08.226 DEBUG Sftp(1)[6] SSH: Allowed authentication methods: password, keyboard-interactive.
2017-06-05 01:06:08.320 ERROR Sftp(1)[6] SSH: Rebex.Net.SshException: No suitable authentication method is supported. Supported methods: 'password,keyboard-interactive'.
   at Rebex.Net.SshSession.KZ(String A, String B, SshPrivateKey C, SshGssApiCredentials D)

Please let me know if I missed something.
by (75.8k points)
If you didn't get "Public key authentication enabled." message, you didn't set up the server correctly.

Please download configured version from http://www.rebex.net/getfile/07eb15eb400d4d6a8b59d5160c5fe37f/RebexTinySftpServer-KeyAuthSample.zip

The .zip contains user1.pri file. Save it to e.g. "c:\data" directory and use it for Public key authentication like this:

sftp.Login("tester", new SshPrivateKey(@"c:\data\user1.pri", "password"));
by (280 points)
I solved the issue. Thanks.
...