Skip to content

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

Closed

Description

@gmlion

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?

Activity

  1. hovek commented on Mar 5, 2018

    @hovek

    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.

  2. kranz912 commented on Jun 8, 2018

    @kranz912

    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.

  3. drieseng commented on Jun 8, 2018

    @drieseng
    Member

    @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.

  4. drieseng commented on Jun 8, 2018

    @drieseng
    Member

    @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?

  5. gmlion commented on Jun 11, 2018

    @gmlion
    Author

    @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?

  6. hotyes commented on Jul 7, 2022

    @hotyes

    hi @gmlion , have you solved this problem ? thanks

  7. igavva commented on Sep 19, 2023

    @igavva

    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

  8. added this to the 2023.0.0 milestone on Sep 19, 2023
  9. WojciechNagorski commented on Sep 23, 2023

    @WojciechNagorski
    Collaborator

    Fixed by #1177 and #1180

  10. WojciechNagorski commented on Oct 10, 2023

    @WojciechNagorski
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions