Ssh2 crate not listing available identities

Hi,

I'm using SSH2 crate to run commands on a remote system. I tried connecting to a remote system to which I've setup remote access using ssh key. I can connect to it using ssh command. But the below code is returning an empty set for available identities:

    let tcp = TcpStream::connect(&format!("{}:22", host))?;
    let mut sess = Session::new().context("creating new session failed")?;
    sess.set_tcp_stream(tcp);
    sess.handshake().context("Handshake failed")?;

    // Try to connect to the system's SSH agent
    let mut agent = sess.agent()?;
    agent.connect()?;
    agent.list_identities()?;
    let identities = agent.identities()?;

    debug!("{:?}", identities);

Could someone please provide me some pointers on why it isnt working as expected ?

Are you sure you added the keys to the agent? They aren't added by default, you usually use ssh-add to add them to the agent until you log out of the computer[1]


  1. i.e. adding a key and then restarting the computer generally means you need to add it again ↩︎

2 Likes

Gotcha, thanks @semicoleon!

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.