Libgit2가 설치된 네트워크에서 ssh를 사용하여 매우 간단한 git 복제본을 작성하려고합니다. 프로세스의 제목에 오류가 발생합니다. 내가 뭘 잘못하고 있는지 모르겠다. 명령 줄을 통해 repo를 복제 할 수 있기 때문에 네트워크 문제가 아니다. 키는 지정된 경로에도 있습니다.Libgit2 - SSH 세션 인증 실패 : 공개 키 파일을 열 수 없습니다.
키가 이미 설정되어 있으므로 컴퓨터에서 ssh를 사용하려는 경우 복제를 시도하고 있는데 암호 만 입력해야하므로 여기에서 다시 정의해야합니다. cred_cb
에서
#include <git2.h>
#include <iostream>
// Callback function
int cred_cb(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload) {
// https://libgit2.github.com/libgit2/#HEAD/group/cred/git_cred_ssh_key_new
return git_cred_ssh_key_new(out, "username",
"~/.ssh/id_rsa.pub", "~/.ssh/id_rsa", "password");
}
int main() {
// Start up libgit2
git_libgit2_init();
// Test clone setup
git_repository *repo = NULL;
const char *url = "ssh://[email protected]/home/git_repo_to_clone";
const char *path = "tmp";
// Test clone
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
clone_opts.fetch_opts.callbacks.credentials = cred_cb;
int error = git_clone(&repo, url, path, &clone_opts);
// Prints the last error message
std::cout << giterr_last()->message << std::endl;
// Clean up
git_libgit2_shutdown();
return 0;
}
인쇄 allowed_types
는 22
을 말한다, 당신은 git_cred의 다른 유형을 반환하려고하면 때문에 (예를 들어, git_cred_userpass_plaintext
) 라이브러리는 callback returned unsupported credentials type
불평, 또한 콜백은 함께 git_clone
를 호출하여 (지정되지 않은 경우 세 번째 매개 변수로 NULL
) 그러면 authentication required but no callback set
이라고 표시됩니다. 분명히 뭔가 빠져있을 수도 있습니다. 도움을 주시면 감사하겠습니다.
편집
내가 대신 git_cred_ssh_key_from_agent(out, "username")
으로 시도하고 누락 된 파일이기는하지만, (망할 놈의 폴더가 복제됩니다) 뭔가를 할 것으로 보인다. 이제는 문제가 cred_cb
과 git_clone
사이의 무한 루프가 되더라도 (앞뒤로 호출되는 것처럼 보입니다).