ssh-rs ✨

Build API Docs LICENSE

English | 简体中文

Rust implementation of ssh2.0 client.

If you encounter any problems in use, welcome issues or PR .

Content

Connection method:

1. Password:

rust use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber; let mut session = ssh::create_session() .username("ubuntu") .password("password") .connect("127.0.0.1:22") .unwrap();

2. Public key:

1. Use key file path:

rust // pem format key path -> /xxx/xxx/id_rsa // the content of the keyfile shall begin with // -----BEGIN RSA PRIVATE KEY----- / -----BEGIN OPENSSH PRIVATE KEY----- // and end with // -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY----- // simply generated by `ssh-keygen -t rsa -m PEM -b 4096` use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber; let mut session = ssh::create_session() .username("ubuntu") .private_key_path("./id_rsa") .connect("127.0.0.1:22") .unwrap();

2. Use key string:

rust // pem format key string: // -----BEGIN RSA PRIVATE KEY----- / -----BEGIN OPENSSH PRIVATE KEY----- // and end with // -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY----- use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber; let mut session = ssh::create_session() .username("ubuntu") .private_key("rsa_string") .connect("127.0.0.1:22") .unwrap();

3. Use them together

Rust use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber; let mut session = ssh::create_session() .username("username") .password("password") .private_key_path("/path/to/rsa") .connect("127.0.0.1:22") .unwrap();

Enable global logging:

``rust use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber; // this will generate some basic event logs // a builder forFmtSubscriber`. let subscriber = FmtSubscriber::builder() // all spans/events with a level higher than INFO (e.g, info, warn, etc.) // will be written to stdout. .withmaxlevel(Level::INFO) // completes the builder. .finish();

tracing::subscriber::setglobaldefault(subscriber).expect("setting default subscriber failed"); ```

Set timeout:

```rust use ssh; use tracing::Level; use tracing_subscriber::FmtSubscriber;

ssh::debug(); let _listener = TcpListener::bind("127.0.0.1:7777").unwrap();

match ssh::createsession() .username("ubuntu") .password("password") .privatekeypath("./idrsa") .timeout(Some(std::time::Duration::from_secs(5))) .connect("127.0.0.1:7777") { Err(e) => println!("Got error {}", e), _ => unreachable!(), } ```

How to use:

  1. Execute a command
  2. Scp files
  3. Run a shell
  4. Run an interactive shell
  5. Connect ssh server w/o a tcp stream
  6. Cofigure your own algorithm list

Algorithm support:

1. Kex algorithms

2. Server host key algorithms

3. Encryption algorithms (client to server)

4. Encryption algorithms (server to client)

5. Mac algorithms (client to server)

6. Mac algorithms (server to client)

7. Compression algorithms (client to server)

8. Compression algorithms (server to client)


☃️ Additional algorithms will continue to be added.