rust-lang / rust-lang/ssh2-rs

Can't connect via private key.

Open
#255 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
566
Forks
163
Avg merge
4h 51m
Merged PRs (30d)
2

Description

I'm trying to connect to a server via private key.

From the CLI, ssh -i ./gen.pem ubuntu@<ip> works as intended, so I know the key, username, port and IP are correct.

So far, this is the code:

let tcp = TcpStream::connect((ip, 22)).unwrap();
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp);
sess.handshake().unwrap();
sess.userauth_pubkey_file("ubuntu", None, Path::new("./gen.pem"), None).unwrap();

But the last line of code fails with:

thread 'main' panicked at 'called Result::unwrap() on an Err value: Error { code: Session(-18), msg: "Username/PublicKey combination invalid" }', src/main.rs:138:10

The same username and private key works with SSH.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the userauth_pubkey_file call in the reported src/main.rs example and inspect how this authentication path handles the supplied key. Compare its behavior with the working SSH command and determine what evidence would distinguish a key-format, username, or library-authentication problem; done means reproducing the failure and documenting or testing a concrete cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.