Table of Contents

How-to guides

Short, task-oriented pages. Each one starts with when to use it, shows focused examples, and ends with the pitfalls and links to the in-depth guides. The examples assume a connected SshClient named client and a CancellationToken named cancellationToken; Getting started shows how to get the client.

Every example on these pages is compiled with the library in CI, so it matches the current API.

Commands and shells

Guide Use it to
Run a command Run a command, with standard input, environment variables or a terminal; read its stdout, stderr and exit status, or throw on failure.
Stream large output Process output as it arrives, feed input, and handle output that does not fit in memory.
Interactive shells and SshExpect Drive a shell or a device CLI with a terminal; wait for prompts and answer them.

Files

Guide Use it to
Transfer files with SFTP Upload, download, resume, split large files over several sessions, verify with a server-side hash, copy directories, work with remote files in place, and call vendor extensions.
Transfer files with SCP Copy files where the server has no SFTP.
IFileSystem and IFileProvider Use remote files through System.IO.Abstractions or Microsoft.Extensions.FileProviders.

Networking

Guide Use it to
Port forwarding and tunnels Reach services behind the server (ssh -L, -R, -D), or give the server a way back.
Jump hosts (ProxyJump) Reach hosts through one or more bastions.
Tune and inspect a connection Set socket options, identify your application to the server, raise the channel window for long links, compress a slow link, read a connection's endpoints and traffic, and re-key on demand.
Tune for throughput Find what limits a slow transfer, and set the channel window, SFTP concurrency, cipher and socket options for it.
Vendor channels and global requests Open a channel type, or send a global request, that the server defines and SshSharp has no API for.

Configuration and trust

Guide Use it to
Use ssh_config and known_hosts Connect by alias, ship your own configuration, read known_hosts.
Verify host keys Choose a host key policy: known_hosts, pinning, certificates, or your own source of truth.
Choose algorithms and authentication methods Restrict or reorder ciphers, key exchanges, MACs and host key algorithms; choose the authentication methods; require larger RSA host keys.

Authentication

Guide Use it to
Keys and the SSH agent Log in with key files, the agent, generated keys, or keys in a TPM, HSM or KMS; export keys to PKCS#8 or PuTTY.
Passwords: prompts, expiry and failures Prompt for a password only when keys did not work, change an expired password, and see why a login failed.
Certificates Log in with OpenSSH user certificates, check certificates, and issue them as a certificate authority.
Kerberos Log in with a Kerberos ticket (Active Directory).

Reliability

Guide Use it to
Keep-alive and reconnecting Notice dead connections and open new ones.
Cancellation and timeouts Bound how long connecting and commands may take.
Logging and diagnostics See what a connection does: logs, traces, metrics, negotiated algorithms.

Applications

Guide Use it to
ASP.NET Core and dependency injection Register SSH endpoints, share a connection, add a health check.
Unit-test code that uses SshSharp Test your logic without a server.
Native AOT Publish a trimmed, ahead-of-time compiled application.
FIPS mode Use only FIPS-approved algorithms.
Migrate from SSH.NET Map SSH.NET code to SshSharp.