#ssh-client #ssh2 #async #ssh

async-ssh2-tokio

Asynchronous and easy-to-use high level ssh client library for rust

38 releases (10 breaking)

Uses new Rust 2024

0.12.2 Jan 26, 2026
0.12.1 Dec 5, 2025
0.12.0 Nov 19, 2025
0.9.0 Jul 16, 2025
0.1.0 Nov 30, 2021

#358 in Network programming

Download history 3590/week @ 2026-01-24 3890/week @ 2026-01-31 3218/week @ 2026-02-07 3369/week @ 2026-02-14 3310/week @ 2026-02-21 3433/week @ 2026-02-28 5584/week @ 2026-03-07 4876/week @ 2026-03-14 3344/week @ 2026-03-21 4535/week @ 2026-03-28 4161/week @ 2026-04-04 5082/week @ 2026-04-11 6040/week @ 2026-04-18 5371/week @ 2026-04-25 4097/week @ 2026-05-02 1108/week @ 2026-05-09

17,654 downloads per month
Used in 11 crates (9 directly)

Custom license

71KB
1.5K SLoC

async-ssh2-tokio

Unit Test Status Lint Status Docs.rs Crates.io

This library is an asynchronous and easy-to-use high level SSH client library for rust with the tokio runtime. Powered by the rust SSH implementation russh.

Features

  • Connect to an SSH Host
  • Execute commands on the remote host
  • Get the stdout and exit code of the command

Install

[dependencies]
tokio = "1"
async-ssh2-tokio = "0.12.2"

Usage

use async_ssh2_tokio::client::{Client, AuthMethod, ServerCheckMethod};

#[tokio::main]
async fn main() -> Result<(), async_ssh2_tokio::Error> {
    // if you want to use key auth, then use following:
    // AuthMethod::with_key_file("key_file_name", Some("passphrase"));
    // or
    // AuthMethod::with_key_file("key_file_name", None);
    // or
    // AuthMethod::with_key(key: &str, passphrase: Option<&str>)
    // if you want to use SSH agent (Unix/Linux only), then use following:
    // AuthMethod::with_agent();
    let auth_method = AuthMethod::with_password("root");
    let mut client = Client::connect(
        ("10.10.10.2", 22),
        "root",
        auth_method,
        ServerCheckMethod::NoCheck,
    ).await?;

    let result = client.execute("echo Hello SSH").await?;
    assert_eq!(result.stdout, "Hello SSH\n");
    assert_eq!(result.exit_status, 0);

    let result = client.execute("echo Hello Again :)").await?;
    assert_eq!(result.stdout, "Hello Again :)\n");
    assert_eq!(result.exit_status, 0);

    Ok(())
}

Running Tests

  1. install docker and docker compose
  2. run shell script ./tests/run_unit_tests.sh

Dependencies

~25–57MB
~1M SLoC