Permission denied (publickey) with SSH.NET - Can connect via FileZilla or Powershell.
See original GitHub issueI’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.
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:6

Top Related StackOverflow Question
I think this can serve as a workaround: https://github.com/sshnet/SSH.NET/issues/825#issuecomment-1139440419
Can someone please refer to my problem and help me please, here is the question: on stackoverflow
I am getting exception Renci.SshNet.Common.SshAuthenticationException: ‘Permission denied (publickey).’
The host is acceesible via LAN, the ip is 192.168.A.XXX and the client IP is 192.168.B.xxx
Only this particular system has the proble, I tried same key pair on another machine, that worked well