Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error loading known_hosts: ; class=Ssh (23) when trying to connect to remote. #937

Closed
tzAcee opened this issue Mar 9, 2023 · 8 comments
Closed

Comments

@tzAcee
Copy link

tzAcee commented Mar 9, 2023

Hey,
I stumble accross an error "error loading known_hosts: ; class=Ssh (23)" when I try to connect to a remote host on our company azure repo.
The git cmd tool works fine of course. So the general SSH configuration should be fine. Seems like the the configuration isn't read out correctly. Do I have to set a config of the repo or something before I connect to the remote?

I wrote a simple test tool for what Im doing:

fn main() { 
   let local_repo_path = r"D:\projects\some_repo_dir"; 
   env::set_var("GIT_SSH_COMMAND", r"ssh -i *ID_RSA_PATH* -o UserKnownHostsFile=*KNOWN_HOSTS_PATH*"); // Added testwise, but it does nothing
   let repo = Repository::open(local_repo_path);
   match repo {
    Ok(repo_unwrap) => {
        let mut remote = repo_unwrap.find_remote("origin").unwrap();
        let res = remote.connect(git2::Direction::Fetch); // also tested connect_auth
        if res.is_err() {
            println!("Could not connect {}", res.err().unwrap());
        }
        },
        Err(_) => println!("Could not open Repo."),
    }
}
@ehuss
Copy link
Contributor

ehuss commented Mar 9, 2023

libgit2 only reads known_hosts from $HOME/.ssh/known_hosts. Do you have a file at that location? Does it have any unusual syntax?

Which version of libgit2-sys are you using? Are you using vendored or system libgit2?

@tzAcee
Copy link
Author

tzAcee commented Mar 10, 2023

libgit2 only reads known_hosts from $HOME/.ssh/known_hosts. Do you have a file at that location? Does it have any unusual syntax?

Which version of libgit2-sys are you using? Are you using vendored or system libgit2?

The Syntax of my file known_hosts should be correct. I tried to recreate it multiple times.
Tbh. I dont know which version of libgit2 im using. I just added with with cargo add git2, so in the cargo.toml the current version is v0.16.1. 😂

But I think fetching the $HOME env variable on windows is an issue or am I wrong?
Since I think it should be %userprofile% on windows, because the HOME env variable isn't set there.
Atleast I have the known_hosts file in '%userprofile%/.ssh/known_hosts'

@ehuss
Copy link
Contributor

ehuss commented Mar 10, 2023

Ah, yea, I recall now that was a problem with the current version. This should be fixed by #935 which reads windows home directories correctly.

@martinellison
Copy link

I am getting the same error on Android. It used to work until recently.

Does anyone know a fix? Or a solution? My app is not working anymore.

@tzAcee
Copy link
Author

tzAcee commented Apr 13, 2023

I dont know whether the fix is released yet.
But if not, you could get the cargo package directly from this repository, since the fix is already merged on master.
If it's an android specific problem the fix wasn't enough.

For Windows I haven't tested it myself yet, so idk if it's working.

@martinellison
Copy link

martinellison commented Apr 15, 2023

As edited: I had a build error, but I think I have fixed it. I think that this was because the git_credentials package is locked to point to version 0.16 of git2 instead of the latest version 0.17.

But I am still getting the error with known_hosts.

@martinellison
Copy link

martinellison commented Apr 15, 2023

Edit: I think my error is different, and needs Android expertise, so I am raising a separate issue on the libgit2 tracker.

The new issue is libgit2/libgit2#6550.

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2023

I'm going to close since this should be fixed in the latest version via #935. If you can still reproduce with 0.17.1, feel free to comment, and please include as much detail as possible to reproduce your environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants