```rust fn main() { let ssh = SSH::new(); let mut session = ssh.getsession("192.168.3.101:22").unwrap(); session.setnonblocking(true).unwrap(); session.setuserandpassword("root".tostring(), "123456".tostring()); session.connect().unwrap(); let mut channel = session.openchannel().unwrap(); let mut shell = channel.open_shell().unwrap();
// thread::sleep(time::Duration::from_millis(500));
// let result = shell.read().unwrap();
// println!("{}", String::from_utf8(result).unwrap());
// shell.close().unwrap();
// session.close().unwrap();
let c1 = Arc::new(Mutex::new(shell));
let c2 = Arc::clone(&c1);
let t1 = thread::spawn(move || {
loop {
let mut x = c1.lock().unwrap().read().unwrap();
if x.is_empty() { continue }
stdout().write(x.as_slice()).unwrap();
stdout().flush();
}
});
let t2 = thread::spawn(move || {
loop {
let mut cm = String::new();
stdin().read_line(&mut cm).unwrap();
c2.lock().unwrap().write(cm.as_bytes()).unwrap();
}
});
t1.join().unwrap();
t2.join().unwrap();
} ```
```rust
fn main() { let ssh = SSH::new(); let mut session = ssh.getsession("192.168.3.101:22").unwrap(); session.setuserandpassword("root".tostring(), "123456".tostring()); session.connect().unwrap(); let mut channel = session.openchannel().unwrap(); let mut exec = channel.openexec().unwrap(); let vec = exec.setcommand("ps -ef |grep ssh").unwrap(); println!("{}", String::fromutf8(vec).unwrap()); session.close().unwrap(); } ```
| algorithms | is supported |
|-------------------------------|---------------|
| curve25519-sha256 | √ |
| ecdh-sha2-nistp256 | √ |
| ssh-ed25519 | √ |
| rsa | √ |
| chacha20-poly1305@openssh.com | √ |
| user auth | is supported |
|------------------|--------------|
| publickey | × |
| password | √ |
| hostbased | × |
| channel | is supported |
|-----------|---------------|
| shell | √ |
| exec | √ |
| subsystem | × |