simple_ssh
simple_ssh is a lightweight, asynchronous Rust library that simplifies SSH operations such as executing remote commands, transferring files via SCP, and interactive PTY sessions. Built on top of the russh and russh-keys crates, it offers a streamlined API for secure and efficient SSH interactions.
Features
- Asynchronous SSH client operations using
tokio - Execute remote shell commands (
cmd,exec,system) - Transfer files securely using the SCP protocol
- Interactive PTY shell sessions with raw mode and auto-resize
- Programmatic PTY sessions via
PtyHandlefor embedding in TUIs - Terminal multiplexer support (1x2, 2x1, 2x2 layouts)
- IPv6 link-local address support with scope ID
- Authentication modes: public key, password, and none
- SSH certificate support for key authentication
- Minimalistic and focused API design
Installation
As a Library
Add simple_ssh to your project's Cargo.toml:
[]
= "0.1.3"
CLI Tools
To install the CLI binaries (simple-ssh and simple-scp), use the cli feature:
This installs both simple-ssh and simple-scp binaries to your cargo bin directory.
Usage
Executing Remote Commands
use Session;
use Result;
async
Transferring Files via SCP
use Session;
use Result;
async
IPv6 Link-Local Addresses
For IPv6 link-local addresses, use the --scope option to specify the network interface:
use Session;
use Result;
async
Programmatic PTY Sessions
For non-interactive PTY sessions where you control the I/O (e.g., embedding in a TUI):
use Session;
use Result;
async
CLI Tools
Two example binaries are provided for command-line use:
simple-ssh
Interactive SSH client with PTY support and terminal multiplexing:
# Interactive shell
# Execute command
# With private key
# IPv6 link-local with scope
# Terminal multiplexer (2 panes stacked vertically)
# Terminal multiplexer (2 panes side by side)
# Terminal multiplexer (4 panes in 2x2 grid)
simple-scp
File transfer utility:
# Transfer file using password authentication
# Transfer file using private key
# With custom port
CLI Options
simple-ssh Options
| Option | Description |
|---|---|
-H, --host <HOST> |
SSH host to connect to (required) |
-u, --user <USER> |
SSH username (default: root) |
-P, --passwd <PASSWD> |
SSH password |
-i, --key <KEY> |
Path to private key file |
-p, --port <PORT> |
SSH port (default: 22) |
--scope <SCOPE> |
IPv6 scope ID (e.g., interface name or number) |
-a, --auth <AUTH> |
Authentication method (password, key, none) |
--mux <MODE> |
Terminal multiplexer mode: 1x2, 2x1, or 2x2 |
simple-scp Options
| Option | Description |
|---|---|
-H, --host <HOST> |
SSH host to connect to (required) |
-u, --user <USER> |
SSH username (default: root) |
-P, --passwd <PASSWD> |
SSH password |
-i, --key <KEY> |
Path to private key file |
-p, --port <PORT> |
SSH port (default: 22) |
--scope <SCOPE> |
IPv6 scope ID (e.g., interface name or number) |
-a, --auth <AUTH> |
Authentication method (password, key, none) |
<LOCAL> |
Local file path to upload |
<REMOTE> |
Remote destination path |
Building
# Development build
# Release build
# Build CLI examples
# Static musl build (for distribution)
The musl build produces a fully static binary with no dynamic library dependencies, suitable for deployment in containerized or minimal environments.
Testing
# Run all tests
# Run specific test
# Run with output
Development Status
simple_ssh is actively developed and provides a stable API for common SSH operations.
The core functionalities including command execution, SCP file transfer, and PTY sessions
are fully implemented and tested. Contributions, issues, and feature requests are welcome!
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
russh - The underlying SSH library used for client and server implementations.