Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@gmlion

Description

@gmlion
Issue body actions

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?

thstarshine

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.