#ssh-client #ssh #async #high-level #execute-command #ssh2

async-ssh2-tokio

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

26 releases

0.8.10 Jun 10, 2024
0.8.8 Apr 30, 2024
0.8.7 Feb 9, 2024
0.8.4 Nov 25, 2023
0.1.0 Nov 30, 2021

#4 in #ssh2

Download history 169/week @ 2024-04-04 103/week @ 2024-04-11 94/week @ 2024-04-18 261/week @ 2024-04-25 305/week @ 2024-05-02 111/week @ 2024-05-09 89/week @ 2024-05-16 104/week @ 2024-05-23 132/week @ 2024-05-30 316/week @ 2024-06-06 187/week @ 2024-06-13 307/week @ 2024-06-20 372/week @ 2024-06-27 547/week @ 2024-07-04 502/week @ 2024-07-11 349/week @ 2024-07-18

1,808 downloads per month
Used in legba

Custom license

38KB
767 lines

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.10"

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

~14–25MB
~361K SLoC