Table of Contents

Class SshClientOptions

Namespace
SshSharp
Assembly
SshSharp.dll

Options for SshClient.

public sealed class SshClientOptions
Inheritance
SshClientOptions
Inherited Members

Properties

AddressFamily

Which addresses of the server to try, as ssh_config's AddressFamily (ssh -4, ssh -6): any (the default), IPv4 only or IPv6 only. Applies to ConnectAsync(string, int, SshClientOptions, CancellationToken); with a Proxy, the proxy resolves the server's name and this does not apply (the connection to the proxy itself uses any family). With a LocalEndPoint too, only addresses that are of the allowed family and of the local endpoint's are tried.

AuthenticationBanner

Receives the server's pre-authentication banner (SSH_MSG_USERAUTH_BANNER, sshd's Banner), for example a legal notice. The text comes from the server: strip control characters before showing it in a terminal.

CASignatureAlgorithms

The signature algorithms a certificate authority may have signed a host certificate with, as ssh_config's CASignatureAlgorithms: for example SshAlgorithmList.Only("ssh-ed25519") to trust only certificates an Ed25519 authority signed. Null (the default) allows SshSharp's set: ssh-ed25519, the three ecdsa-sha2-nistp* and rsa-sha2-512, rsa-sha2-256. The list can only narrow that set: SHA-1 ssh-rsa and the FIDO sk-* algorithms, which ssh's defaults have, are never accepted. A host certificate signed with an algorithm the list leaves out cannot be used, as one that has expired: KnownHostsVerifier logs a warning and checks its key as a plain key, as ssh does. FipsMode does not apply to it.

ChangePassword

Answers the server's request to change an expired password (SSH_MSG_USERAUTH_PASSWD_CHANGEREQ, RFC 4252 section 8) with the new one, or null to decline. The password just sent is sent again as the old one, with the new one; when the server refuses the new password it can ask again (at most 3 times), and when it accepts it, the connection is authenticated (or goes on to the next method the server requires). Null (the default), or declining, leaves the password unchanged: the attempt counts as failed (PasswordChangeRequired) and the other methods are tried.

ChannelMaxPacketSize

The most data the server may put in one packet on a channel (RFC 4254 section 5.1). Larger packets mean fewer of them, and less work per byte, for bulk transfers. It applies to every channel, as ChannelWindowSize does, and is capped at it. Default 32 KiB, as OpenSSH. Between 1 KiB and 255 KiB: SshSharp accepts packets of up to 256 KiB, as OpenSSH does, and the rest is room for the packet's header, padding and MAC. What the client sends is limited by what the server asks for, not by this.

ChannelTimeouts

Idle timeouts by channel type, as OpenSSH's ChannelTimeout (9.2+) sets them on the client: a channel that carries no data in either direction for its type's timeout is closed, with an ordinary CLOSE. Its streams then end as when the server closes it, and a forwarded or tunnelled connection's local socket is closed. Empty by default (no timeouts). For example [new("direct-tcpip", TimeSpan.FromMinutes(10)), new("session", TimeSpan.Zero), new("*", TimeSpan.FromHours(1))]: the first entry whose type pattern matches applies (see SshChannelTimeout).

ChannelWindowSize

The window each channel grants the server (RFC 4254 section 5.2): how many bytes it may send on a channel before SshSharp has consumed some. One channel moves at most one window per round trip, so on a link with a large bandwidth-delay product (a fast, distant link) a larger window makes a single download, command output or tunnel faster: 2 MiB per 100 ms of round trip is about 20 MiB/s. Each channel can then hold up to this much received data that your code has not read yet. It applies to every channel: sessions, SFTP, SCP, tunnels and forwarded connections. Default 2 MiB, as OpenSSH. Between 1 KiB and 1 GiB. The window is topped up once half of it has been consumed, or 64 MiB for a window over 128 MiB: older Dropbear never uses more than 500,000,000 bytes of a window, and would otherwise wait for an adjustment that never came.

Ciphers

The ciphers to offer, as ssh_config's Ciphers: for example SshAlgorithmList.Prepend("chacha20-poly1305@openssh.com"). Null (the default) offers SshSharp's defaults. FipsMode still removes ChaCha20-Poly1305.

Compression

Compress the connection, as ssh's Compression yes (ssh -C): offer zlib@openssh.com before none. The server decides whether it is used; Algorithms tells what was negotiated. Compression starts only after authentication succeeds (OpenSSH's delayed compression; plain zlib, which starts before it, is not supported by design) and lasts for the rest of the connection. Off by default, as in ssh: it helps on slow links and with text, costs CPU on fast links, and packet lengths can reveal what compressed well when secrets and data an attacker chooses share the connection. SshSharp compresses with Huffman coding only, as OpenSSH does, which limits that. On .NET 8 only what the server sends is compressed. Allowed in FipsMode: zlib is not a cryptographic algorithm.

ConfigureSocket

Sets socket options on the TCP connection to the server: TCP keep-alive, buffer sizes, the type of service (DSCP), and so on. It is called with the new socket before it connects (after it is bound to LocalEndPoint, if set), so options that must be set before the handshake, such as the receive buffer size that TCP window scaling depends on, take effect. Null (the default) leaves the system's defaults; SshSharp itself turns Nagle's algorithm off (NoDelay).

ConnectTimeout

How long the connection attempt may take, as ssh_config's ConnectTimeout: resolving the name and the TCP connection (or the connection through Proxy), the SSH handshake, host key verification and authentication, the time spent in your callbacks included (KeyboardInteractive, a host key prompt). When it passes, the attempt fails with an SshException whose Reason is Timeout (its inner exception is a TimeoutException); a cancelled CancellationToken still ends it with an OperationCanceledException. It ends with the connection: once connected, operations are bounded by their own tokens. Null (the default) or InfiniteTimeSpan sets no limit but the token. Over a stream you opened (ConnectAsync(Stream, SshClientOptions, bool, CancellationToken)) it bounds the handshake and authentication.

ConnectionAttempts

How many times to try the network connection, one second apart, as ssh_config's ConnectionAttempts: the TCP connection to the server, or to the first of the JumpHosts, or to the Proxy. Only failures to reach it are tried again (refused, unreachable, timed out), never a name that does not resolve, a proxy's refusal, a failed handshake or authentication, and ConnectTimeout bounds all the attempts together. Default 1. Used by ConnectAsync(string, int, SshClientOptions, CancellationToken); ignored when connecting over a stream you opened.

FipsMode

Restrict key exchange, host key, cipher and MAC algorithms to FIPS-approved ones (NIST curves and DH groups, RSA/ECDSA, AES, HMAC-SHA2). Curve25519, Ed25519 and ChaCha20-Poly1305 are excluded. This limits what is negotiated; it does not make the process FIPS-validated.

ForwardAgent

Forward this agent to the server (ssh -A, ForwardAgent yes): sessions ask the server to offer it, so programs there (ssh, git) can authenticate onward with your keys. Null (the default) forwards nothing. Only forward to servers you trust: while connected, anyone with enough rights on the server can use the agent to sign with your keys (not read them). An in-process agent (FromKeys(params SshPrivateKey[])) is answered here, with no agent process; ForwardAgentFilter decides what the server's side may do with either kind.

ForwardAgentFilter

Decides each request a program on the server makes of the forwarded agent (ForwardAgent): which keys it lists and whether each signature is made. Return true to allow. It can be asynchronous, to ask the user (as ssh-add -c does) or another service. Null (the default) allows everything, as ssh -A does.

Gssapi

Authenticate with Kerberos (gssapi-with-mic) when the server offers it, before the other methods, as ssh does with GSSAPIAuthentication yes. Null (the default) does not try it. Needs .NET 10 (IsSupported).

HostKeyAlgorithms

The host key algorithms to accept from the server, as ssh_config's HostKeyAlgorithms: for example SshAlgorithmList.Only("ssh-ed25519"). Certificate algorithms (-cert-v01@openssh.com) may be listed too. Null (the default) accepts SshSharp's defaults. When the HostKeyVerifier trusts a certificate authority for the host, the certificate versions of the allowed algorithms are asked for first, as ssh does. FipsMode still removes Ed25519.

HostKeyAlias

The name to look the host key up under (OpenSSH's HostKeyAlias), instead of the host name. Needed to use known_hosts when connecting over a Stream, where the host name is not known.

HostKeyVerifier

Decides whether to trust the server's host key: a KnownHostsVerifier, Pinned(params string[]), or your own (FromDelegate(Func<SshHostKeyContext, CancellationToken, ValueTask<bool>>)). There is deliberately no default: accepting unknown keys silently would defeat the purpose of host authentication.

JumpHosts

Jump hosts to reach the server through, first to last, as ssh -J and ssh_config's ProxyJump: the client connects to the first, reaches each next one through the one before, and the server through the last. Each hop logs in and verifies its host key with its own Options; these options (credentials, HostKeyVerifier) are the destination's alone and never offered to a hop. Proxy, LocalEndPoint, AddressFamily, ConfigureSocket, ConnectionAttempts and StaggeredConnectDelay apply to the first network connection, which is the first hop's (a hop's own are not used). ConnectTimeout bounds the whole chain. Disposing the client closes every hop. Empty (the default) connects directly. Used by ConnectAsync(string, int, SshClientOptions, CancellationToken); ignored when connecting over a stream you opened.

KeepAliveCountMax

After this many keep-alive intervals without hearing from the server, the connection is declared dead and fails with Timeout (OpenSSH's ServerAliveCountMax). Default 3.

KeepAliveInterval

Send a keep-alive when the server has been silent this long (OpenSSH's ServerAliveInterval). Null (the default), Zero (as ServerAliveInterval 0) and InfiniteTimeSpan send none, and so does an interval longer than about 49 days, the longest a timer waits. Keep-alives detect a dead connection and stop idle NAT and firewall timeouts from dropping it.

KexAlgorithms

The key exchange methods to offer, as ssh_config's KexAlgorithms: for example SshAlgorithmList.Remove("diffie-hellman-group*"), or SshAlgorithmList.Only("mlkem768x25519-sha256", "curve25519-sha256"). Null (the default) offers SshSharp's defaults, post-quantum hybrids first. ML-KEM methods are dropped where the platform lacks ML-KEM (before .NET 10), and FipsMode still removes what it excludes.

KeyboardInteractive

Answers keyboard-interactive authentication (RFC 4256): one-time codes, PAM prompts, or a password the server asks for this way. Called once per round with the server's questions; return one answer per prompt, or null to give up on the method. Tried after PrivateKeys and before Password, like ssh. Unlike PasswordProvider, the method is not retried after the server refuses the answers: it is tried once per walk of the authentication order.

LocalEndPoint

The local address (and usually port 0) to connect from, as ssh -b, for machines on several networks; null lets the system choose. Only destination addresses of the same family are tried. Used by ConnectAsync(string, int, SshClientOptions, CancellationToken), also for the connection to Proxy.

Logger

Receives diagnostics (connection, algorithms, authentication outcome, channels, rekeys). Never receives passwords or command text. Default: no logging.

Macs

The MACs to offer, as ssh_config's MACs: for example SshAlgorithmList.Only("hmac-sha2-512-etm@openssh.com"). Null (the default) offers SshSharp's defaults. AEAD ciphers (AES-GCM, ChaCha20-Poly1305) authenticate themselves and use no MAC.

MaxCommandOutputBytes

The most output (stdout plus stderr) RunCommandAsync(string, CancellationToken) and its overloads will collect before failing. Default 128 MiB.

MaxForwardedConnections

The most connections the server may have forwarded to this client at once, across all remote forwardings (port, dynamic and Unix-socket) and the agent channels of agent forwarding (ForwardAgent). Each one makes a connection on this machine (an agent channel, one to the local agent), so this bounds what a misbehaving server can make it open; above it, the server's channel is refused (resource shortage) and its client sees the connection fail. Default 1000.

NumberOfPasswordPrompts

How many times PasswordProvider may be asked on one connection, as ssh_config's NumberOfPasswordPrompts. Default 3, as in ssh; 0 never asks. A given Password is not counted.

ObscureKeystrokeTiming

Hide the timing of keystrokes in sessions with a terminal, as OpenSSH's ObscureKeystrokeTiming (9.5+) does: while someone types, small writes to StandardInput are sent only once per interval (a write completes when its interval comes), and the intervals with nothing typed carry a chaff packet of the same size, for a random 1 to 3 seconds after the last key. Someone watching the encrypted traffic then cannot tell keys, or the time between them, from the packets. Larger writes (256 bytes or more, such as a paste) go at once. Chaff is sent only to servers that announce ping@openssh.com (OpenSSH 9.5+). Null (the default) sends every write at once. ssh uses 20 ms, and so does ConnectAsync(string, SshConfigConnectOptions?, CancellationToken) unless the config says otherwise. Between 1 ms and 1 second, as ssh allows.

Password

The password, if used. Tried after PrivateKeys and KeyboardInteractive with the password method. When the server offers only keyboard-interactive (common with PAM) and there is no handler, it answers a round that asks for exactly one hidden input. With a PasswordProvider too, this password is tried first, and the provider is asked only if the server refuses it.

PasswordProvider

Asks for the password when authentication reaches it, as ssh prompts user@host's password:: only after the keys (and Kerberos) did not log in, so an interactive tool prompts only when it has to. It is called again after each refused password, at most NumberOfPasswordPrompts times per connection; return null to stop asking. It answers the password method, and keyboard-interactive the way Password does (a round that asks for exactly one hidden input) when there is no KeyboardInteractive handler. A Password that is set is tried first.

PreferredAuthentications

The authentication methods to try and their order, as ssh_config's PreferredAuthentications: any of gssapi-with-mic, publickey, keyboard-interactive and password. A method that is left out is not tried, even when its credentials are set. Null (the default) uses ssh's order: gssapi-with-mic (only with Gssapi), publickey, keyboard-interactive, password. A method is tried only when the server offers it and its credentials are set (PrivateKeys, Password, KeyboardInteractive, Gssapi).

PrivateKeys

Keys for public-key authentication, tried in order (load them with LoadAsync(string, string?, CancellationToken)). The client does not dispose them. A key whose private material is in this process (loaded, parsed or generated) signs its request straight away; a key held by an agent or an SshKeySigner is offered first, and signs only if the server would accept it.

Proxy

An HTTP or SOCKS proxy to reach the server through, for ConnectAsync(string, int, SshClientOptions, CancellationToken). The server's host name is resolved by the proxy. With JumpHosts, it carries the connection to the first jump host instead. Ignored when connecting over a stream you opened.

PubkeyAcceptedAlgorithms

The signature algorithms public-key authentication may use, as ssh_config's PubkeyAcceptedAlgorithms: for example SshAlgorithmList.Only("ssh-ed25519"), or SshAlgorithmList.Remove("rsa-sha2-*"). A key in PrivateKeys is offered only with an algorithm the list allows, and is skipped when it allows none of the key's: a plain key under its own type (ssh-ed25519, ecdsa-sha2-nistp256), an RSA key as rsa-sha2-512 or rsa-sha2-256, and a key with a certificate under the certificate's algorithm (ssh-ed25519-cert-v01@openssh.com), which its plain one does not allow. An RSA key signs with the first of the list's RSA algorithms that the server accepts (its server-sig-algs). Null (the default) allows every algorithm a key has, in the key's own order (RSA: SHA-512 first). FipsMode does not apply to it.

RekeyAfterBytes

Negotiate new keys after this many bytes have been transferred under the current ones. Default 1 GiB (RFC 4253 section 9). Values above 64 GiB (2^32 cipher blocks, the limit OpenSSH applies) are capped, and keys are also renewed every 2^31 packets. As in OpenSSH, the client starts a re-exchange only once the user is authenticated; one the server starts is carried out at any time.

RekeyAfterTime

Negotiate new keys after the current ones have been in use this long. Default 1 hour (RFC 4253 section 9). Like RekeyAfterBytes, it applies only once the user is authenticated.

RequiredRsaSize

The smallest RSA host key accepted, in bits, as ssh_config's RequiredRSASize; a smaller one fails the connection with an SshHostKeyException. Default 2048 (ssh's default is 1024). At least 1024, the least ssh accepts. A value above 2048 also applies to the RSA authority that signed a host certificate, as in OpenSSH master; a certificate's authority is never accepted under 2048 bits, whatever the value.

StaggeredConnectDelay

Races the server's addresses instead of trying them one after another, as RFC 8305 ("Happy Eyeballs") describes: when its name has several addresses, the next is tried once the one before has had this long to connect or has failed, whichever comes first, IPv6 and IPv4 addresses taking turns, and the first connection made is used. A server whose first address does not answer (a broken IPv6 route, say) is then reached after this delay, not after the system's connect timeout, which can be minutes. RFC 8305 recommends 250 milliseconds. Null (the default) tries the addresses in order, each until it fails, as ssh does.

UserName

The user to authenticate as.

VersionAddendum

A comment appended to this client's identification line, which then reads SSH-2.0-SshSharp_1.2.3 comment (RFC 4253 section 4.2), for example to tell your application's connections apart in the server's logs. Null (the default) sends none. The line is sent before encryption starts, so anyone on the network path can read it, and servers log it: put no secrets or personal data in it.