Class SshEndpointOptions
- Namespace
- SshSharp.Extensions.DependencyInjection
- Assembly
- SshSharp.Extensions.DependencyInjection.dll
One named SSH endpoint, registered with services.AddSshClient(name): where to connect and how to authenticate. Mutable, so
configuration can bind to it (.BindConfiguration("Ssh:Deploy")). Set either ConfigAlias, to connect through
ssh_config, or Host.
public sealed class SshEndpointOptions
- Inheritance
-
SshEndpointOptions
- Inherited Members
Properties
- AcceptNewHostKeys
Accept and record the key of a host not yet in KnownHostsFiles (
StrictHostKeyChecking accept-new). Off by default: an unknown host fails the connection. A changed key always fails it.
- AddressFamily
Which of the server's addresses to try (AddressFamily):
Any,Inet(IPv4 only) orInet6(IPv6 only), for exampleInetwhere a host's IPv6 address is published but not reachable. With ConfigAlias, it overrides ssh_config'sAddressFamily. Null (the default) tries any address, or leaves it to ssh_config.
- Compression
Compress the connection after authentication (
zlib@openssh.com, see Compression), as ssh'sCompression yes: it helps on slow links and with text, and costs CPU on fast ones. With ConfigAlias, it overrides ssh_config'sCompression. Null (the default) does not compress, or leaves it to ssh_config.
- ConfigAlias
Connect by this
ssh_configalias instead (ProxyJump, IdentityFile, known_hosts and the rest come from the user's and the system's ssh_config). Host, Port, UserName, PrivateKeyFiles, KnownHostsFiles, AcceptNewHostKeys (ssh_config'sStrictHostKeyCheckingdecides), KeepAliveInterval (itsServerAliveIntervaldoes) and ConfigureClientOptions are then ignored; Password is still offered, to the destination only. PrivateKeys, HostKeyFingerprints, Proxy and JumpHosts cannot be combined with it (validation fails), as ssh_config decides keys, host keys, proxies and jump hosts there.
- ConfigureClientOptions
Adjusts the client options built from these settings (a custom host key verifier, keys held elsewhere, a custom proxy, ...): receives the services and the options built so far, and returns the options to use. The options it receives already hold JumpHosts (as JumpHosts) and the agent's keys: copy them into new options. Not used with ConfigAlias.
- ConnectTimeout
How long one connection attempt, handshake and authentication included, may take (default 30 seconds; at most about 24 days, MaxValue milliseconds, as ConnectTimeout allows). It is also the ConnectTimeout of the client options built from these settings, which ConfigureClientOptions may shorten; it cannot extend the attempt past this limit.
- Host
The server's host name or address. Required unless ConfigAlias is set.
- HostKeyFingerprints
Trust only these host keys, as Pinned(params string[]) does. Each entry is one of:
- a SHA-256 fingerprint in OpenSSH's format (
SHA256:and 43 base64 characters, asssh-keygen -lfprints it); - a public key line, as the server's
/etc/ssh/ssh_host_ed25519_key.pubholds it (ssh-ed25519 AAAA... comment, read by Parse(string)); - a known_hosts line (
host ssh-ed25519 AAAA...), asssh-keyscanprints it. Its host field is not checked: the line pins the key. Marked lines (@cert-authority,@revoked) fail validation.
They replace known_hosts: setting KnownHostsFiles, AcceptNewHostKeys or ConfigAlias as well fails validation, so it is never unclear which of them decides. List more than one to allow for a host key rotation.
- a SHA-256 fingerprint in OpenSSH's format (
- JumpHosts
Jump hosts (bastions) to reach Host through, first to last, as
ssh -Jdoes (see JumpHosts). Each has its own user, credentials and host key settings, and is offered only those; the endpoint's password and keys go to Host alone. With Proxy, the proxy carries the connection to the first hop. ConnectTimeout bounds the whole chain. Cannot be combined with ConfigAlias, where ssh_config'sProxyJumpapplies.
- KeepAliveInterval
Send keep-alives at this interval, so a dead connection is noticed (none by default, or when zero or InfiniteTimeSpan). Any other negative value fails validation. Not used with ConfigAlias, where ssh_config's
ServerAliveIntervalapplies.
- KnownHostsFiles
The known_hosts files that hold the server's host keys (default: the user's
~/.ssh/known_hosts). New keys are recorded in the first one when AcceptNewHostKeys is set.
- MaxReconnectDelay
The longest wait between the shared connection's reconnection attempts (default 1 minute).
- Password
A password, tried after any keys. Keep it out of source control: bind it from a secret store.
- Port
The server's port (default 22).
- PrivateKeyFiles
Private key files (OpenSSH, PEM or PuTTY format) to authenticate with, tried in order.
- PrivateKeyPassphrase
The passphrase of encrypted PrivateKeyFiles.
- PrivateKeys
Private keys given as values instead of files (from environment variables, a mounted secret, Key Vault or user secrets), each with its own optional passphrase. They are offered after PrivateKeyFiles, in order. Each is checked when the settings are validated (at start with
ValidateOnStart), and read again for each connection, which does not keep it after authenticating. Cannot be combined with ConfigAlias.
- Proxy
An HTTP or SOCKS proxy to connect through, as a URI:
http://proxy.example.com:3128,socks5://,socks5h://,socks4://orsocks4a://, with optional percent-encodeduser:password@(see FromUri(Uri)). Bind it from a secret store when it holds a password. Cannot be combined with ConfigAlias, where ssh_config'sProxyJumporProxyCommandapply.
- ReconnectDelay
The wait before the shared connection's first reconnection attempt; it doubles after each failure (default 1 second).
- UseAgent
Whether to offer the keys of the user's SSH agent. Without ConfigAlias, true offers them after PrivateKeyFiles and PrivateKeys, and null or false does not (the default). With ConfigAlias, null leaves it to ssh_config (
IdentityAgent, as ssh does), false turns the agent off, and true uses the agent below in place of ssh_config'sIdentityAgent(which decides only when there is none). The agent is the one registered in the container as SshAgent (FromKeys(params SshPrivateKey[]) for keys held in this process); without one, it is the environment's (FromEnvironmentAsync(CancellationToken)). An agent that is not running is skipped, as ssh skips it.
- UserName
The user to log in as. Required unless ConfigAlias is set (then ssh_config, or the local user, decides).