Search code examples
c#sshopensshssh.netssh-agent

Use C# SSH.NET with private key stored in ssh-agent


I'm migrating some of our C# code from username/password Linux connectivity to using public/private keys (with passphrase). I've stored the private key in the Windows ssh-agent and all works well using ssh user@server.

Now I need to use the private key from the agent with SSH.NET... this is where I'm stuck.

How can I tell the SshClient to use the agent key, instead of passing the private keys file?

I'd like something like this....

sshClient = new SshClient(server, port, user, /*use ssh-agent please*/)

Solution

  • Afaik, SSH.NET does not support authentication using an authentication agent.

    Quick google search reveals SshNet.Agent library, which should extend SSH.NET to support the authentication agent:
    https://github.com/darinkes/SshNet.Agent

    I have no experience with it though.