Table of Contents

Class SshAgent

Namespace
SshSharp
Assembly
SshSharp.dll

An SSH agent (ssh-agent, the Windows OpenSSH agent service, or any agent speaking the same protocol) that holds private keys and signs with them, so the keys never enter this process. List its keys with GetKeysAsync(CancellationToken) and pass them in PrivateKeys; every signature is then made by the agent.

public sealed class SshAgent
Inheritance
SshAgent
Inherited Members

Remarks

Each request opens a new connection to the agent, so an agent restarted between connections is picked up. Signatures for authentication are made on a connection bound to the SSH session (session-bind@openssh.com), so keys added with destination constraints (ssh-add -h) work as they do with ssh.

Constructors

SshAgent(string)

An agent at path: a Unix domain socket, or on Windows a named pipe such as \.\pipe\openssh-ssh-agent.

Properties

Path

The socket or pipe the agent listens on.

Methods

AddKeyAsync(SshPrivateKey, SshAgentKeyConstraints?, CancellationToken)

Adds key to the agent, as ssh-add does, optionally with constraints (a lifetime, or a confirmation for each use). A key paired with a certificate is added with it. Adding a key the agent already holds replaces its constraints.

FromEnvironment()

The user's agent, as ssh finds it: SSH_AUTH_SOCK; on Windows, when that is not set, the OpenSSH agent service's pipe, or PuTTY's Pageant (0.75 and later) when only Pageant is running. Null when there is none to try. Whether an agent is actually running shows on the first request.

FromPageant()

PuTTY's Pageant (0.75 and later), on the named pipe it creates for the current user (\.\pipe\pageant.<user>.<hash>), or null when Pageant is not running or this is not Windows. Its keys work like any agent's.

GetKeysAsync(CancellationToken)

The keys the agent holds, ready for PrivateKeys. Keys of types SshSharp cannot authenticate with (DSA, for example) are left out.

LockAsync(string, CancellationToken)

Locks the agent with passphrase (ssh-add -x): until UnlockAsync(string, CancellationToken), it lists no keys and signs nothing.

QueryExtensionsAsync(CancellationToken)

The protocol extensions the agent supports (RFC 9987's query extension), for example session-bind@openssh.com. An agent that does not implement query yields an empty list.

RemoveAllKeysAsync(CancellationToken)

Removes every key from the agent (ssh-add -D).

RemoveKeyAsync(SshPrivateKey, CancellationToken)

Removes one key from the agent (ssh-add -d): one from GetKeysAsync(CancellationToken), or the key a file holds.

UnlockAsync(string, CancellationToken)

Unlocks an agent locked with LockAsync(string, CancellationToken) (ssh-add -X).