Table of Contents

Namespace SshSharp

Classes

KnownHostsLookup

The name and port a host key is looked up under in known_hosts (see KnownHostsLookup).

KnownHostsVerifier

Verifies host keys against OpenSSH known_hosts files, with StrictHostKeyChecking semantics:

  • A recorded key that matches is trusted; one listed as @revoked is always refused.
  • A different key of a recorded type ("the host key has changed") is refused, except with No, which accepts it as ssh does: the connection goes on, but password and keyboard-interactive authentication, agent forwarding and port forwarding are disabled on it, so a man in the middle gets no password and no access to this side.
  • An unknown key is refused (Yes), offered to AskHostKey, or recorded and trusted (AcceptNew, No). AcceptNew refuses it when keys of other types are already recorded for the host, so a man in the middle cannot get a weaker key type accepted silently.
  • A host certificate from an @cert-authority for the host is trusted while it is valid for the host. One that cannot be used (expired, not yet valid, not issued for the name connected to, or signed with an algorithm CASignatureAlgorithms leaves out) is logged as a warning, and its key is then checked as a plain key by the rules above, as ssh does; so is a certificate from no listed authority. A certificate whose key or authority is @revoked is refused.

New keys are appended to the first user file. The file is rewritten only by UpdateHostKeys, to remove keys the server no longer announces.

SshAddKeyToAgentPrompt

A key about to be added to the agent under ssh_config's AddKeysToAgent ask, passed to ConfirmAddKeyToAgent. It carries what ssh's prompt shows ("Add key file (comment) to agent?"), and the key's fingerprint.

SshAgent

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.

SshAgentDestination

One destination constraint on an agent key (OpenSSH's restrict-destination-v00@openssh.com, ssh-add -h): the key may be used to authenticate to To when reached from From; from this machine when From is null. A key used through agent forwarding needs a constraint for each hop: ssh-add -h jump -h "jump>dest" is two destinations. The agent enforces them through the session binding (session-bind@openssh.com) that ssh and SshSharp send.

SshAgentHost

A host in an agent destination constraint (SshAgentDestination): its name, the user (for the destination only), and the host keys that identify it, or certificate authorities whose host certificates do.

SshAgentHostKey

A host key in a destination constraint, in SSH wire format; with IsCertificateAuthority, a CA key whose host certificates count.

SshAgentKeyConstraints

Limits on a key added to an agent (AddKeyAsync(SshPrivateKey, SshAgentKeyConstraints?, CancellationToken)), as ssh-add -t and ssh-add -c set them.

SshAgentRequest

One request that a program on the server makes of a forwarded agent, as ForwardAgentFilter sees it: which key, what for, and what is known of where the signature goes.

SshAlgorithmList

An algorithm list for KexAlgorithms, HostKeyAlgorithms, Ciphers, Macs, PubkeyAcceptedAlgorithms or CASignatureAlgorithms, in the forms ssh_config's Ciphers, KexAlgorithms, MACs, HostKeyAlgorithms, PubkeyAcceptedAlgorithms and CASignatureAlgorithms take: a list that replaces SshSharp's defaults (Only(params string[])), or a change to them that keeps up with new defaults in later versions (Append(params string[]), Prepend(params string[]), Remove(params string[])).

SshAllowedSigners

An allowed-signers file (ssh-keygen's ALLOWED SIGNERS format, git's gpg.ssh.allowedSignersFile): which keys may sign as which principals, for SshSignature verification as ssh-keygen -Y verify and -Y find-principals do.

SshAuthenticationAttempt

One authentication attempt and what became of it, listed by Attempts. It names the method and, for a key, its fingerprint: never a password, an answer or the user name.

SshAuthenticationException

The server refused every authentication method that was tried.

SshAuthenticationPrompt

One question in a keyboard-interactive round.

SshCertificate

An OpenSSH certificate (PROTOCOL.certkeys): a public key signed by a certificate authority, limited to some principals, a validity window, and options. Presented by servers as host keys and used by clients for public-key authentication. Read one with Parse(string), check one with IsValidFor(SshPublicKey, SshCertificateType, string, DateTimeOffset, out string?) (or its parts, VerifySignature() and IsValidAt(DateTimeOffset)), and issue one with SshCertificateBuilder.

SshCertificateBuilder

Issues an OpenSSH certificate (PROTOCOL.certkeys) as its certificate authority, as ssh-keygen -s does: set what the certificate allows, then sign it with the authority's key (SignAsync(SshPrivateKey, CancellationToken)). The key can be one an SSH agent, a key vault or a KMS holds (FromSigner(SshKeySigner, string?)), so the authority's private key need never be in the process.

SshChannelTimeout

A channel idle timeout, as OpenSSH's ChannelTimeout sets one (type=interval): channels of ChannelType with no data in either direction for Timeout are closed by the client. See ChannelTimeouts.

SshClient

An authenticated SSH client connection: run commands over it. Create one with ConnectAsync(Stream, SshClientOptions, bool, CancellationToken).

SshClientOptions

Options for SshClient.

SshCommandException

A remote command did not succeed (EnsureSuccess()): it exited with a non-zero ExitStatus, was ended by ExitSignal, or ended without reporting either. StandardError holds the end of what it wrote to standard error. The message names the status or the signal only: neither the command nor its output is in it, since exception messages often end up in logs.

SshCommandInput

What RunCommandAsync(string, SshSessionOptions?, SshCommandInput?, CancellationToken) writes to the command's standard input: bytes, text or a stream. The input is written while the output is collected, and end-of-file follows it, so commands that read to the end of their input (cat, sh -s, tee) finish.

SshCommandResult

The outcome of a remote command.

SshConfigConnectOptions

Options for ConnectAsync(string, SshConfigConnectOptions?, CancellationToken), which takes everything else from ssh_config: host name, port, user, identity files, known_hosts and StrictHostKeyChecking, algorithms, ProxyJump, ProxyCommand, ServerAliveInterval, ConnectTimeout, ConnectionAttempts and AddressFamily. A few of these can be set here instead, overriding what the configuration says: Port, ConnectTimeout, ConnectionAttempts, AddressFamily, KeepAliveInterval, KeepAliveCountMax and Compression, as HostKeyVerifier and Proxy do for host key checking and the first network hop.

SshCustomChannel

A channel of a type SshSharp has no API of its own for, opened with OpenChannelAsync(string, ReadOnlyMemory<byte>, CancellationToken). Disposing it (or Stream) closes the channel.

SshDynamicPortForwarder

A SOCKS proxy (dynamic forwarding, ssh -D) started by ForwardDynamicPortAsync(IPEndPoint, CancellationToken): applications connect to LocalEndPoint as a SOCKS 4, 4a or 5 proxy (CONNECT, no authentication), and each connection is made by the server to the address the application asked for. Started with credentials (ForwardDynamicPortAsync(IPEndPoint, NetworkCredential?, CancellationToken)), it takes SOCKS 5 with a user name and password only. Dispose it to stop listening and close the connections.

SshException

The base class for errors raised by SshSharp when talking SSH.

SshExitSignal

The signal that ended a remote program, from the server's exit-signal (RFC 4254 section 6.10).

SshExpect

Drives an interactive program, as expect does: wait until its output shows a prompt or other text, then send the next input. Wrap a shell session (StartShellAsync(SshSessionOptions?, CancellationToken), usually with a terminal) and use ExpectAsync(string, CancellationToken), ReadLineAsync(CancellationToken) and SendLineAsync(string, CancellationToken); timeouts are CancellationTokens.

SshExpectMatch

A match found by SshExpect.

SshForwardedConnection

One connection the server forwarded to a handler in this process: a remote forwarding started with ForwardRemotePortAsync(string, int, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken) or ForwardRemoteUnixSocketAsync(string, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken). The handler owns Stream: disposing it closes the connection, and it is disposed for the handler when the handler returns.

SshGlobalRequestResult

The server's answer to SendGlobalRequestAsync(string, ReadOnlyMemory<byte>, CancellationToken).

SshGssapiOptions

Kerberos authentication (gssapi-with-mic, RFC 4462; ssh's GSSAPIAuthentication yes), set on Gssapi. The ticket comes from the platform: the logon session on Windows (SSPI), the credential cache (kinit) elsewhere (MIT or Heimdal GSS-API). Needs .NET 10; on .NET 8 the method is not offered.

SshHostKey

The host key the server proved possession of during key exchange. Decide whether to trust it in HostKeyVerifier.

SshHostKeyContext

What a SshHostKeyVerifier is asked to decide: which host this is and the key it proved it holds.

SshHostKeyException

The server's host key was not trusted, changed, or revoked, or the server could not prove it holds the key.

SshHostKeyPrompt

Why a KnownHostsVerifier in Ask mode is asking.

SshHostKeyScanOptions

Options for ScanHostKeysAsync(string, int, SshHostKeyScanOptions?, CancellationToken).

SshHostKeyUpdate

A change to known_hosts that UpdateHostKeys is about to make, for ConfirmHostKeyUpdate.

SshHostKeyVerifier

Decides whether to trust a server's host key. Use KnownHostsVerifier for OpenSSH known_hosts behaviour, Pinned(params string[]) for fixed fingerprints or Pinned(params SshPublicKey[]) for fixed keys, or FromDelegate(Func<SshHostKeyContext, CancellationToken, ValueTask<bool>>) for your own logic.

SshJumpHost

A jump host (bastion) to reach the server through, as ssh -J and ssh_config's ProxyJump do: list them, first to last, in JumpHosts. Each hop is a complete SSH connection of its own, with its own Options: user, credentials, host key verification, algorithms and keep-alives. The next hop (or the destination) is reached through a direct-tcpip channel the hop opens, and the hop only relays bytes it cannot decrypt.

SshKeyRevocationList

A list of revoked keys, as sshd's RevokedKeys and ssh's RevokedHostKeys read it: an OpenSSH Key Revocation List (KRL, the binary file ssh-keygen -k writes), or a text file of public keys, one per line. Check a user's key or certificate against it before trusting it, as ssh-keygen -Q does.

SshKeySigner

Signs with a private key that SshSharp never sees: one in Azure Key Vault or AWS KMS, in an HSM behind PKCS#11, on a smart card. Derive from it, then pass it to FromSigner(SshKeySigner, string?) to use the key like any other (for public key authentication, with a certificate, or for SSH signatures). For a key that .NET's RSA or ECDsa already holds, including non-exportable Windows CNG keys, use FromRsa(RSA, string?) or FromECDsa(ECDsa, string?).

SshKeyboardInteractiveRequest

A round of keyboard-interactive authentication (RFC 4256): the server's questions, answered by KeyboardInteractive. All text comes from the server: strip control characters before showing it in a terminal.

SshLocalPortForwarder

A local port forwarding (ssh -L) started by ForwardLocalPortAsync(IPEndPoint, string, int, CancellationToken) or its overload: connections to LocalEndPoint are relayed through the server to RemoteHost:RemotePort, or to the Unix socket RemoteSocketPath there. Dispose it to stop listening and close the forwarded connections.

SshLocalSocketForwarder

A local forwarding that listens on a Unix socket (ssh -L /local/socket:host:port or ssh -L /local/socket:/remote/socket), started by ForwardLocalUnixSocketAsync(string, string, int, CancellationToken) or its overload: connections to the socket LocalSocketPath are relayed through the server to RemoteHost:RemotePort, or to the Unix socket RemoteSocketPath on the server. The socket file is owner-only. Dispose it to stop listening, close the forwarded connections and remove the socket file.

SshNegotiatedAlgorithms

The algorithms a connection negotiated (they can change at a key re-exchange). See Algorithms.

SshPasswordChangeRequest

The server's request for a new password (SSH_MSG_USERAUTH_PASSWD_CHANGEREQ, RFC 4252 section 8), passed to ChangePassword: the password was right, but has expired. The server can ask again when it refuses the new password (too short, reused), with a new Prompt that usually says why.

SshPasswordPrompt

A request for a password, passed to PasswordProvider when authentication reaches a password (the password method, or a keyboard-interactive round that asks for exactly one hidden input). It carries what an interactive tool shows, as ssh's user@host's password: prompt does.

SshPrivateKey

A private key for public-key authentication. Load one with Parse(string, string?) or LoadAsync(string, string?, CancellationToken). Supported formats: the OpenSSH key format (BEGIN OPENSSH PRIVATE KEY, as ssh-keygen writes by default, also passphrase-protected), PuTTY .ppk (versions 2 and 3, also encrypted), PKCS#8 (BEGIN PRIVATE KEY, and BEGIN ENCRYPTED PRIVATE KEY for RSA and ECDSA), and PKCS#1/SEC1 PEM (BEGIN RSA PRIVATE KEY, BEGIN EC PRIVATE KEY), also encrypted the traditional way (Proc-Type: 4,ENCRYPTED with AES-128/192/256-CBC, as ssh-keygen -m PEM writes it). Passphrase-protected OpenSSH keys are read with every cipher ssh-keygen -Z offers, chacha20-poly1305@openssh.com included. Key types: Ed25519, ECDSA (nistp256/384/521) and RSA (2048 bits or more). A key held here can be written in the OpenSSH format (ToOpenSshPrivateKey(string?, int)), PKCS#8 (ToPkcs8PrivateKey(string?)) or PuTTY's (ToPuttyPrivateKey(string?)), or saved to a file in any of them (SaveAsync(string, SshPrivateKeyFormat, string?, CancellationToken)).

SshProtocolException

The peer sent data that violates the SSH protocol (malformed packet, bad length, unexpected message).

SshProxy

An HTTP or SOCKS proxy to reach the SSH server through, for networks that allow outbound connections only that way. Set it as Proxy or Proxy, or open a stream with ConnectAsync(string, int, CancellationToken) and pass it to ConnectAsync(Stream, SshClientOptions, bool, CancellationToken).

SshPublicKey

An SSH public key: what a .pub file, an authorized_keys line or a known_hosts line holds. Read one with Parse(string) (a line of text) or FromBlob(ReadOnlyMemory<byte>, string?) (the SSH wire format), and get one from a key the library already has: GetPublicKey(), GetPublicKey(), GetPublicKey(), GetPublicKey(). Key types: Ed25519, ECDSA (nistp256/384/521), RSA, and the FIDO security-key types sk-ssh-ed25519@openssh.com and sk-ecdsa-sha2-nistp256@openssh.com.

SshRemotePortForwarder

A remote port forwarding (ssh -R) started by ForwardRemotePortAsync(string, int, string, int, CancellationToken): the server listens on BindAddress:RemotePort, and each connection made to it is relayed to LocalHost:LocalPort as reached from this machine. A remote dynamic forwarding (ForwardRemoteDynamicPortAsync(string, int, Func<string, int, bool>?, CancellationToken), IsDynamic) instead answers each connection as a SOCKS proxy and connects where it asks, and a forwarding to a handler (ForwardRemotePortAsync(string, int, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken)) passes each connection to the application's code. Dispose it to cancel the forwarding on the server and close the forwarded connections.

SshRemoteSocketForwarder

A remote Unix-socket forwarding (ssh -R /remote/socket:target) started by ForwardRemoteUnixSocketAsync(string, string, int, CancellationToken): the server listens on the Unix socket RemoteSocketPath, and each connection made to it is relayed to a TCP port (LocalHost:LocalPort) or a Unix socket (LocalSocketPath) reached from this machine, or passed to the application's handler (ForwardRemoteUnixSocketAsync(string, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken)). Dispose it to cancel the forwarding on the server and close the forwarded connections.

SshSession

A shell or command running on the server (an SSH session channel), with its input and output as streams. Start one with StartShellAsync(SshSessionOptions?, CancellationToken) or StartCommandAsync(string, SshSessionOptions?, CancellationToken); dispose it to close the channel.

SshSessionOptions

Options for StartShellAsync(SshSessionOptions?, CancellationToken) and StartCommandAsync(string, SshSessionOptions?, CancellationToken).

SshSharpInfo

Build and identification information about the library.

SshSignRequest

One signature asked of an SshKeySigner: the algorithm, the data, and what the signature is for, so a signer can apply a policy (a key service that allows authentication only, say), log what it signs, or ask its user.

SshSignature

An SSH signature over a file or a message (OpenSSH's SSHSIG format, ssh-keygen -Y sign), as git uses for signed commits with gpg.format=ssh. Make one with SignAsync(SshPrivateKey, ReadOnlyMemory<byte>, string, string, CancellationToken) (any key, an agent's too), write it with ToString(), and read one with Parse(string).

SshTelemetry

The names SshSharp publishes diagnostics under. Subscribe to SourceName for traces (ActivitySource) and metrics (Meter), for example with OpenTelemetry: .AddSource(SshTelemetry.SourceName) and .AddMeter(SshTelemetry.SourceName). Nothing is recorded unless something listens, and no secrets (passwords, keys, command text) are ever recorded.

SshTerminalOptions

A pseudo-terminal request (RFC 4254 section 6.2).

Structs

SshHostKeyVerdict

A verifier's decision about a host key.

Enums

SshAgentOperation

What a program on the server asks of a forwarded agent (Operation).

SshAuthenticationOutcome

What became of one authentication attempt (see Attempts).

SshCertificateType

Whether an OpenSSH certificate certifies a user or a host.

SshFailureReason

Why an SSH operation failed.

SshKeyType

A key type to generate with Generate(SshKeyType, string?, int).

SshPrivateKeyFormat

A private key file format to write with SaveAsync(string, SshPrivateKeyFormat, string?, CancellationToken).

SshProxyType

The kind of proxy an SshProxy speaks.

SshSignaturePurpose

What a signature made with a private key is for (Purpose).

SshTerminalMode

Terminal mode opcodes (RFC 4254 section 8, and IUTF8 from RFC 8160), named as in POSIX termios.