Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renci.SshNet.Common.SshAuthenticationException: Permission denied (publickey) #373

Closed
gmlion opened this issue Jan 17, 2018 · 9 comments
Closed
Milestone

Comments

@gmlion
Copy link

gmlion commented Jan 17, 2018

I'm trying to connect to an Ubuntu server with my private key, but I can't get it working

let execution () =
    let connectionInfo = new ConnectionInfo(host, "root", new PrivateKeyAuthenticationMethod("./resources/keys/id_rsa"))
    use client = new SshClient(connectionInfo)
    do client.Connect()
    ()
    
do execution ()

The code is a F# script but I guess it's readable.
I tested the file to be reachable (looks like the exception if the path is wrong is the same) and I also tried using the key with ssh cli, succesfully. So the key should be good.

EDIT: the same error occurs using both the NuGet package and the current develop branch on GitHub
EDIT 2: i managed to get it working. This is the working code:

let execution () =
    let connectionInfo = new ConnectionInfo(host, "root", new PrivateKeyAuthenticationMethod("root", new PrivateKeyFile("./resources/keys/id_rsa")))
    use client = new SshClient(connectionInfo)
    do client.Connect()
    ()
    
do execution ()

I see it's a bit redundant (having to specify twice the username). Is there a better way, similar to the multi-factor example?

@hovek
Copy link

hovek commented Mar 5, 2018

Windows C#, .NET 4.5. I get permission denied just out of the blue, it worked fine and suddenly throws permission denied for every file, FileZilla works fine.

@kranz912
Copy link

kranz912 commented Jun 8, 2018

I got the same issue. It was working on my development machine running windows 10. When I deployed it to our production environment I get this message. Both are pointing to the same private key file.

@drieseng
Copy link
Member

drieseng commented Jun 8, 2018

@gmlion: in the first code snippet you actually specified "./resources/keys/id_rsa" as user name, hence the authentication failure.

I agree that it's a bit weird to specify the user name twice. Please submit a separate issue for this.

@drieseng
Copy link
Member

drieseng commented Jun 8, 2018

@hovek, @kranz912: If you have more information (eg. server logs), please submit a separate issue.

@kranz912: Were you actually accessing the same SSH server on both your development machine and your production environment?

@gmlion
Copy link
Author

gmlion commented Jun 11, 2018

@drieseng The single argument PrivateKeyAuthenticationMethod constructor is used in the multi-factor-authentication example in the README, I suppose it no longer works that way?

@hotyes
Copy link

hotyes commented Jul 7, 2022

hi @gmlion , have you solved this problem ? thanks

@igavva
Copy link

igavva commented Sep 19, 2023

A simple solution.

Add this line in /etc/ssh/sshd_config.

PubkeyAcceptedAlgorithms +ssh-rsa
Afterwards, restart the sshd service to make the new settings come into effect.

$ sudo systemctl restart sshd

@WojciechNagorski
Copy link
Collaborator

Fixed by #1177 and #1180

@WojciechNagorski
Copy link
Collaborator

Version 2023.0.0 has been published https://www.nuget.org/packages/SSH.NET/2023.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants