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_hostsfiles, withStrictHostKeyCheckingsemantics:- A recorded key that matches is trusted; one listed as
@revokedis always refused. - A different key of a recorded type ("the host key has changed") is refused, except with No.
- 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.
New keys are appended to the first user file. The file is rewritten only by UpdateHostKeys, to remove keys the server no longer announces.
- A recorded key that matches is trusted; one listed as
- 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 -tandssh-add -cset them.
- 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 asssh-keygen -Y verifyand-Y find-principalsdo.
- 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.
- SshChannelTimeout
A channel idle timeout, as OpenSSH's
ChannelTimeoutsets 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.
- 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 and AddressFamily.
- 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. 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
expectdoes: 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.
- SshGssapiOptions
Kerberos authentication (
gssapi-with-mic, RFC 4462; ssh'sGSSAPIAuthentication 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_hostsbehaviour, Pinned(params string[]) for fixed fingerprints, or FromDelegate(Func<SshHostKeyContext, CancellationToken, ValueTask<bool>>) for your own logic.
- 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): connections to LocalEndPoint are relayed through the server to RemoteHost:RemotePort. Dispose it to stop listening and close the forwarded connections.
- SshNegotiatedAlgorithms
The algorithms a connection negotiated (they can change at a key re-exchange). See Algorithms.
- 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, asssh-keygenwrites by default, also passphrase-protected), PuTTY.ppk(versions 2 and 3, also encrypted), PKCS#8 (BEGIN PRIVATE KEY, andBEGIN ENCRYPTED PRIVATE KEYfor RSA and ECDSA), and PKCS#1/SEC1 PEM (BEGIN RSA PRIVATE KEY,BEGIN EC PRIVATE KEY). Key types: Ed25519, ECDSA (nistp256/384/521) and RSA (2048 bits or more).
- 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).
- 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. 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. 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
sessionchannel), 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 withgpg.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
- 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).
- 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
IUTF8from RFC 8160), named as in POSIXtermios.