Skip to content

SSH.NET Extension to authenticate via OpenSSH Agent and PuTTY Pageant

License

Notifications You must be signed in to change notification settings

stevesobol/SshNet.Agent

 
 

Repository files navigation

SshNet.Agent

SSH.NET Extension to authenticate via OpenSSH Agent and PuTTY Pageant

License NuGet Nuget

CodeQL .NET-Ubuntu .NET-Windows NuGet

Status

Works on my machine - WIP

Currently builds it's own fork of SSH.NET.

Needs this Branch: https://github.com/darinkes/SSH.NET-1/tree/agent_auth

.NET Frameworks

  • .NET 4.0
  • netstandard 2.0
  • netstandard 2.1

Note: Only with netstandard 2.1 it contains support for Unix Domain Sockets to use ssh-agent on Linux.

Keys

  • ssh-ed25519
  • ecdsa-sha2-nistp256
  • ecdsa-sha2-nistp384
  • ecdsa-sha2-nistp521
  • ssh-rsa with 2048, 3072, 4096 or 8192 KeyLength

Features

  • Auth
  • Adding Keys
  • Getting Keys
  • Removing Keys
  • Removing all Keys

Agent Protocol Documentation

draft-miller-ssh-agent-02

Usage

OpenSSH Agent

var agent = new SshAgent();

var keyFile = new PrivateKeyFile("test.key");
agent.AddIdentity(keyFile);

var keys = agent.RequestIdentities();

using var client = new SshClient("ssh.foo.com", "root", keys);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

PuTTY Pageant

var agent = new Pageant();

var keyFile = new PrivateKeyFile("test.key");
agent.AddIdentity(keyFile);

var keys = agent.RequestIdentities();

using var client = new SshClient("ssh.foo.com", "root", keys);
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

Resharper Warning

If you want to avoid the Resharper Warning "Co-variant array conversion": https://www.jetbrains.com/help/resharper/CoVariantArrayConversion.html

var agent = new Pageant();

var keyFile = new PrivateKeyFile("test.key");
agent.AddIdentity(keyFile);

var keys = agent.RequestIdentities();

using var client = new SshClient("ssh.foo.com", "root", keys.ToArray<IPrivateKeyFile>());
client.Connect();
Console.WriteLine(client.RunCommand("hostname").Result);

About

SSH.NET Extension to authenticate via OpenSSH Agent and PuTTY Pageant

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%