feat: add ssh-rs
This commit is contained in:
19
__shell/sshrs/src/main.rs
Normal file
19
__shell/sshrs/src/main.rs
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user