LibSshNet
A wrapper around libssh2 for .NET
Install / Use
/learn @NullOpsDevs/LibSshNetREADME
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.
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:
- Managed Layer: Clean, idiomatic C# API with async/await support (not true async)
- Interop Layer: P/Invoke bindings to libssh2 native library
- 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.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
