question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Permission denied (publickey) with SSH.NET - Can connect via FileZilla or Powershell.

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

3reactions
gregolskycommented, Jun 2, 2022
0reactions
SibghatUcommented, May 10, 2023

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connecting to SFTP with key file using SSH.NET ...
In my case I got the message ( (Permission denied (publickey))) when PasswordAuthentication was missing. The server needed the certificate ...
Read more >
Error 'Permission denied (publickey,password)' - ssh
First set PasswordAuthentication yes in file sshd_config at the destination machine, and then do ssh-copy-id user@host , log in, and then it ...
Read more >
Troubleshoot "Permission denied (Publickey)" or ...
Verify that the file permissions within the operating system are correct and that the correct SSH public key is in the authorized_keys file...
Read more >
SSH Permission denied (publickey)
Your home directory, the .ssh directory and the authorized_keys file have strict permission requirements. (see manpage of sshd (8) on ~/.ssh/ ...
Read more >
Baaahhh... authentication failing after upgrading ubuntu
Suddenly I couldn't ssh to ubuntu machine from my windows desktop. ... The error is “Failed to connect: Permission denied (publickey)”.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found