How to run a command on remote system through SSH?

Not exactly a rust question, but more of an SSH library question. I am following the example given in Russh documentation for making a client at russh - Rust, and I have the following significant code:

  let mut session = russh::client::connect(config, SocketAddr::from_str("").unwrap(), sh).await.unwrap();
  if session.authenticate_future(std::env::var("USER").unwrap(), key.clone_public_key().unwrap(), agent).await.1.unwrap() {
      let mut channel = session.channel_open_session().await.unwrap();
      channel.exec(true, "ls -lah").await.unwrap();
      if let Some(resp) = channel.wait().await {

However, the execution is stuck at the line:
let mut channel = session.channel_open_session().await.unwrap();

After looking through some other SSH libraries, I can see that after the execution is done, I have to read the output back, but in my code using Russh, I am not reaching the execute part.

Can someone advice me on how to use Russh library for executing commands on a remote system?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.