feat: add ssh-rs

This commit is contained in:
2022-09-02 23:58:14 +08:00
parent bce6338c2b
commit 338d2720ac
5 changed files with 874 additions and 1 deletions

19
__shell/sshrs/src/main.rs Normal file
View File

@@ -0,0 +1,19 @@
use ssh_rs::{Session, ssh};
use ssh_rs::key_pair::KeyPairType;
fn main() {
let mut session: Session = ssh::create_session();
let user_home = rust_util::util_os::get_user_home().unwrap();
// pem format key path -> /xxx/xxx/id_rsa
// KeyPairType::SshRsa -> Rsa type algorithm, currently only supports rsa.
session.set_user_and_key_pair_path(
"root",
format!("{}/.ssh/id_rsa", user_home),
KeyPairType::SshRsa,
).unwrap();
session.connect("hatter.ink:22").unwrap();
let exec = session.open_exec().unwrap();
let v = exec.send_command("ls -l -a --color ~/").unwrap();
println!("{}", String::from_utf8_lossy(&v).to_string());
}