honzasp / makiko Goto Github PK
View Code? Open in Web Editor NEWAsynchronous SSH client library in pure Rust
Home Page: https://honzasp.github.io/makiko/
License: The Unlicense
Asynchronous SSH client library in pure Rust
Home Page: https://honzasp.github.io/makiko/
License: The Unlicense
This library looks really nice and im trying to compare it against russh.
I would appreciate a section in the readme that explains what differentiates makiko from russh.
One difference I can see is that russh also supports writing ssh servers.
I'm hoping that makiko focusing on writing clients makes it better for that.
Thanks!
I'm trying to use makiko to do some remote automation work where I need SSH port forwarding, but I'm having the issue where sometimes there are long periods between when the SSH channel is actually used, and so sometimes they end up having timed out by the time I need to use them again, which would require some moderately complex abstraction to be able to work around.
It would be nice if makiko instead supported SSH-level keep-alive ร la OpenSSH's ServerAliveInterval
/ServerAliveCountMax
which send null packets through the encrypted channel.
When I start the shell and execute a command with no output, such as 'cat empty.txt,' the session event receiver gets blocked and doesn't return empty stdout data.
`
let stream = TcpStream::connect("192.168.255.167:22").await?;
let config = makiko::ClientConfig::default_compatible_less_secure();
let (client, mut client_rx, client_fut) = makiko::Client::open(stream, config)?;
let h1 = tokio::spawn(async move {
let e = client_fut.await;
});
let h2 = tokio::spawn(async move {
loop {
// Wait for the next event.
let event = client_rx.recv().await;
let Ok(Some(event)) = event else { break };
match event {
// Handle the server public key: for now, we just accept all keys, but this makes
// us susceptible to man-in-the-middle attacks!
makiko::ClientEvent::ServerPubkey(_pubkey, accept) => {
// println!("Server pubkey type {}, fingerprint {}",pubkey.type_str(),pubkey.fingerprint());
accept.accept();
}
makiko::ClientEvent::AuthBanner(b) => {
println!("{:?}", b);
}
_ => {}
}
}
});
let r = client.auth_password("root".into(), "123456".into()).await;
println!("{:?}",r);
let channel_config = makiko::ChannelConfig::default();
let (session, mut session_rx) = client.open_session(channel_config).await?;
let session_wait = tokio::spawn(async move {
loop {
// Wait for the next event.
let event = session_rx
.recv()
.await.unwrap();
println!("{:?}",event);
// Exit the loop when the session has closed.
let Some(event) = event else {
break;
};
}
});
let r = session.shell().unwrap().ignore();
session.send_stdin(Bytes::copy_from_slice(b"ls -hl\n")).await?;
session.send_stdin(Bytes::copy_from_slice(b"echo test > test.txt\n")).await?;
session.send_stdin(Bytes::copy_from_slice(b"cat empty.txt\n")).await?;
let r = session_wait.await?;
println!("finished");`
error: `box_syntax` has been removed
--> /home/york/.cargo/registry/src/index.crates.io-6f17d22bba15001f/guard-0.5.1/src/lib.rs:426:20
|
426 | let foo = (box 42, [1, 2, 3]);
| ^^^^^^
|
help: use `Box::new()` instead
|
426 | let foo = (Box::new(42), [1, 2, 3]);
| ~~~~~~~~~~~~
client_fut rst Err(AlgoNegotiate(AlgoNegotiateError { algo_name: "key exchange", our_algos: ["curve25519-sha256", "[email protected]"], their_algos: ["diffie-hellman-group14-sha1", "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521"] })),
does'nt support "diffie-hellman-group14-sha1" yet?
I ran this code against an amazon EC2 instance running ubuntu.
let (client, mut client_rx, client_fut) = Client::open(
tokio::net::TcpStream::connect((address, 22)).await.unwrap(),
ClientConfig::default(),
)
.unwrap();
tokio::task::spawn(async move {
if let Err(err) = client_fut.await {
tracing::error!("Error while driving ssh connection: {err}");
}
});
tokio::task::spawn(async move {
loop {
// Wait for the next event.
let event = client_rx
.recv()
.await
.expect("Error while receiving client event");
// Normally a client would perform TOFU authentication (known_hosts file) against the server here.
// But that would be pointless for us since we only connect to each server once.
if event.is_none() {
// connection is closed
return;
}
}
});
let privkey = makiko::keys::decode_pem_privkey_nopass(private_key.as_bytes())
.expect("Could not decode a private key from PEM")
.privkey()
.cloned()
.expect("Private key is encrypted");
let auth_res = client
.auth_pubkey("ubuntu".to_owned(), privkey, &SSH_ED25519)
.await
.expect("Error when trying to authenticate");
I can connect to this instance fine with russh and I am passing in the same public ip and private ED25519 key that I use with russh.
The final .expect
fails with: 'Error when trying to authenticate: AuthAborted'
And I also get a tracing error: Error while driving ssh connection: server public key was not accepted
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.