SSH.NET Extension to authenticate via OpenSSH Agent and PuTTY Pageant
- .NET 4.8
- 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.
- ssh-ed25519
- ecdsa-sha2-nistp256
- ecdsa-sha2-nistp384
- ecdsa-sha2-nistp521
- ssh-rsa with 2048, 3072, 4096 or 8192 KeyLength
- Auth
- Adding Keys
- Getting Keys
- Removing Keys
- Removing all Keys
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);
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);
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);