Crate async_ssh [] [src]

High-level library for asynchronous SSH connections.

This crate presents a higher-level asynchronous interface for issuing commands over SSH connections. It's built on top of thrussh, a pure-Rust implementation of the SSH protocol.

At its core, the crate provides the notion of an SSH [Session], which can have zero or more [Channel]s. Each [Channel] executes some user-defined command on the remote machine, and implements AsyncRead and (eventually) AsyncWrite to allow reading from and writing to the remote process respectively. For those unfamiliar with asynchronous I/O, you'll likely want to start with the functions in tokio-io::io.

The code is currently in a pre-alpha stage, with only a subset of the core features implemented, and with fairly gaping API holes like thrussh types being exposed all over the place or error types not being nice to work with.


let key = thrussh_keys::load_secret_key("/path/to/key", None).unwrap();

let mut core = tokio_core::reactor::Core::new().unwrap();
let handle = core.handle();
let ls_out = tokio_core::net::TcpStream::connect(&"".parse().unwrap(), &handle)
    .and_then(|c| Session::new(c, &handle))
    .and_then(|session| session.authenticate_key("username", key))
    .and_then(|mut session| session.open_exec("ls -la"));

let channel =;
let (channel, data) =, Vec::new())).unwrap();
let status =;

println!("{}", ::std::str::from_utf8(&data[..]).unwrap());
println!("exited with: {}", status);



A channel used to communicate with a process running at a remote host.


A newly opened, but not yet established channel.


A future that will eventually resolve to the exit status of a process running on a remote host.


A newly established, unauthenticated SSH session.


An established and authenticated SSH session.