Skip to content

NullOpsDevs/LibSshNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NullOpsDevs.LibSsh

A modern, cross-platform .NET library providing managed bindings for libssh2, enabling SSH operations including remote command execution, SCP file transfers, and advanced terminal (PTY) features.

NuGet License: MIT .NET .NET .NET .NET .NET .NET Documentation

Features

Category Feature Method(s) Supported
Authentication
Password authentication Authenticate(PasswordCredential) βœ…
Public key authentication Authenticate(PublicKeyCredential) βœ…
SSH agent authentication Authenticate(SshAgentCredential) βœ…
Host-based authentication Authenticate(HostBasedCredential) βœ…
Keyboard-interactive authentication - ❌
Session Management
Connection Connect, ConnectAsync βœ…
Host key retrieval GetHostKey βœ…
Host key verification GetHostKeyHash βœ…
Session timeout configuration SetSessionTimeout, DisableSessionTimeout βœ…
Keepalive configuration ConfigureKeepAlive, SendKeepAlive βœ…
Method preference configuration SetMethodPreferences βœ…
Secure default algorithms SetSecureMethodPreferences βœ…
Negotiated method inspection GetNegotiatedMethod βœ…
File Transfer (SCP)
File upload WriteFile, WriteFileAsync βœ…
File download ReadFile, ReadFileAsync βœ…
Command Execution
One-shot command execution ExecuteCommand, ExecuteCommandAsync βœ…
Streaming command execution ExecuteCommandStreaming, ExecuteCommandStreamingAsync βœ…
Exit code retrieval SshCommandResult.ExitCode βœ…
Exit signal retrieval SshCommandResult.ExitSignal βœ…
stdout/stderr separation SshCommandResult.Stdout, SshCommandResult.Stderr βœ…
Terminal (PTY)
PTY allocation CommandExecutionOptions.RequestPty βœ…
Terminal type selection CommandExecutionOptions.TerminalType βœ…
Terminal modes CommandExecutionOptions.TerminalModes βœ…
Window size configuration CommandExecutionOptions.TerminalWidth/Height βœ…
Interactive shell mode - ❌
Error Handling
Typed exceptions SshException βœ…
Detailed error messages SshException.Message βœ…
60+ error code mappings SshError enum βœ…
Advanced Features
Host key type detection SshHostKey.Type βœ…
Microsoft.Extensions.Logging integration Constructor ILogger parameter βœ…
Cross-platform native binaries Bundled in NuGet package βœ…
Global library cleanup LibSsh2.Exit() βœ…
Thread Safety
SshSession is NOT thread-safe. - ❌
Multiple SshSessions are supported. - βœ…

Installation

Install via NuGet Package Manager:

dotnet add package NullOpsDevs.LibSsh

Or via Package Manager Console:

Install-Package NullOpsDevs.LibSsh

Supported Platforms

  • .NET 9.0+
  • Windows (x64)
  • Linux (x64, ARM64)
  • macOS (x64, ARM64/Apple Silicon)

Quick Start

Quickstart guide is available here.

Building from Source

Prerequisites

  • .NET 9.0 SDK or later
  • Git

Build Steps

# Clone the repository
git clone https://github.com/NullOpsDevs/LibSshNet.git
cd LibSshNet

# Restore dependencies and build
dotnet restore
dotnet build

# Run tests
cd NullOpsDevs.LibSsh.Test
docker compose up -d
dotnet run

Architecture

The library consists of three layers:

  1. Managed Layer: Clean, idiomatic C# API with async/await support (not true async)
  2. Interop Layer: P/Invoke bindings to libssh2 native library
  3. Native Layer: Pre-compiled libssh2 binaries for all supported platforms

All native dependencies are bundled in the NuGet package for zero-configuration deployment.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

This library uses libssh2, a client-side C library implementing the SSH2 protocol.

libssh2 is licensed under BSD License.