SSH.NET: Permission denied (publickey) with SSH.NET - Can connect via FileZilla or Powershell.
I’m trying to extend our SFTP capability to allow connection via key-authentication.
The code examples are very straightforward (thanks for that) and I’m pretty sure I’ve done it right:
connectionInfo = New ConnectionInfo(e.Host, e.Port, e.Username, GetAuthenticationMethods(e))
with GetAuthenticationMethods(e) giving me an array of AuthenticationMethods, depending on the provided information:
[...]
authMethod.Add(New PasswordAuthenticationMethod(e.Username, e.Password))
[...]
If e.FilePassphrase = "" Then
authMethod.Add(New PrivateKeyAuthenticationMethod(e.Username, New PrivateKeyFile(keyFile)))
ElseIf e.FilePassphrase <> "" Then
authMethod.Add(New PrivateKeyAuthenticationMethod(e.Username, New PrivateKeyFile(keyFile, e.FilePassphrase)))
End If
[...]
m_Client = New SftpClient(connectionInfo)
m_Client.Connect()
I have a Server set up and generated keys. Originally, I had a ssh-rsa key, giving me a openssh key type: ssh-rsa is not supported Error while trying to instantiate the PrivateKeyAuthenticationMethod. (afaict this should be supported but is not yet in the NuGet package, is there any ETA on when this will be available?)
I converted this key to PEM, which gets me one step further but now I get a Permission denied (publickey). Error.
I can connect to the server without issues using either the PEM or the ssh-rsa key over FileZilla or ssh on console.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 15
I think this can serve as a workaround: https://github.com/sshnet/SSH.NET/issues/825#issuecomment-1139440419