-
Notifications
You must be signed in to change notification settings - Fork 156
Open
Labels
Description
Hello,
I'm new to both rust and ssh2-rs, so excuse me if I'm just doing something stupid.
Here's simplest case that I can't get working:
use std::net::TcpStream;
use ssh2::Session;
use std::io::Read;
fn main() {
let remote_user = "john";
let remote_addr = "tester.example.com:22";
let remote_cmd = "echo $SSH_AUTH_SOCK; ssh-add -l";
let stream = TcpStream::connect(&remote_addr).unwrap();
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(stream);
sess.handshake().unwrap();
sess.userauth_agent(remote_user).unwrap();
let mut channel = sess.channel_session().unwrap();
channel.handle_extended_data(ssh2::ExtendedData::Merge).unwrap();
// channel.request_auth_agent_forwarding().unwrap();
channel.exec(remote_cmd).unwrap();
let mut out = String::new();
channel.read_to_string(&mut out).unwrap();
channel.close().unwrap();
channel.wait_close().unwrap();
let _exit_status = channel.exit_status().unwrap();
println!("{}", out);
}It works as expected if there's no request_auth_agent_forwarding():
Could not open a connection to your authentication agent.
But if I start agent forwarding it just hangs there. If i remove the ssh-add part and leave only the echo I see the SSH_AUTH_SCOKET is set up ok.
I think the problem is that ssh-agent connection coming back from server to client somehow messes with my read_to_string(). I guess the local agent is supposed to write() back to server at this moment and that's why my read would block.
Any ideas how to go about this?