#ssh-client #async #ssh2

async-ssh2-tokio

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

30 releases

0.8.14 Mar 15, 2025
0.8.12 Aug 17, 2024
0.8.11 Jul 28, 2024
0.8.7 Feb 9, 2024
0.1.0 Nov 30, 2021

#189 in Network programming

Download history 408/week @ 2024-12-14 120/week @ 2024-12-21 154/week @ 2024-12-28 281/week @ 2025-01-04 440/week @ 2025-01-11 303/week @ 2025-01-18 793/week @ 2025-01-25 595/week @ 2025-02-01 637/week @ 2025-02-08 381/week @ 2025-02-15 633/week @ 2025-02-22 665/week @ 2025-03-01 600/week @ 2025-03-08 932/week @ 2025-03-15 725/week @ 2025-03-22 449/week @ 2025-03-29

2,804 downloads per month
Used in 5 crates (4 directly)

Custom license

48KB
1K 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.8.14"

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>)
    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

~18–47MB
~739K SLoC