Skip to content

Latest commit

 

History

History
125 lines (96 loc) · 2.95 KB

README_ZH.md

File metadata and controls

125 lines (96 loc) · 2.95 KB

ssh-rs ✨

English | 简体中文

rust实现的ssh2.0客户端。

如果在使用中遇到任何问题,欢迎 issues 或者 PR

连接方式:

1. 密码连接:

fn main() {
    let session = ssh::create_session()
        .username("ubuntu")
        .password("password")
        .connect("ip:port")
        .unwrap()
        .run_local();
}

2. 公钥连接:

fn main() {
    let session = ssh::create_session()
        .username("ubuntu")
        .password("password")
        .private_key_path("./id_rsa") // 文件地址
        .connect("ip:port")
        .unwrap()
        .run_local();
}    
fn main() {
    let session = ssh::create_session()
        .username("ubuntu")
        .password("password")
        .private_key("rsa_string") // 文件字符串
        .connect("ip:port")
        .unwrap()
        .run_local();
}

启用全局日志:

本crate现在使用兼容logtracing crate记录log 使用下面的代码片段启用log

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

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

设置全局超时时间:

ssh::create_session().timeout(Some(std::time::Duration::from_secs(5)));

使用样例

  • 更多使用样例请参考examples目录
  1. 执行单个命令
  2. 通过scp传输文件
  3. 启动一个pty
  4. 运行一个交互式的shell
  5. 使用非tcp连接
  6. 自行配置密码组

算法支持:

1. 密钥交换算法

  • curve25519-sha256
  • ecdh-sha2-nistp256

2. 主机密钥算法

  • ssh-ed25519
  • rsa-sha2-512
  • rsa-sha2-256
  • rsa-sha (features = ["deprecated-rsa-sha1"])
  • ssh-dss (features = ["deprecated-dss-sha1"])

3. 加密算法

  • chacha20-poly1305@openssh.com
  • aes128-ctr
  • aes192-ctr
  • aes256-ctr
  • aes128-cbc (features = ["deprecated-aes-cbc"])
  • aes192-cbc (features = ["deprecated-aes-cbc"])
  • aes256-cbc (features = ["deprecated-aes-cbc"])
  • 3des-cbc (features = ["deprecated-des-cbc"])

4. MAC算法

  • hmac-sha2-256
  • hmac-sha2-512
  • hmac-sha1

5. 压缩算法

  • none
  • zlib (behind feature "zlib")

☃️ 会继续添加其它算法。