簡體   English   中英

LibGit2 SSH 認證失敗

[英]LibGit2 SSH Authenication Failing

我正在嘗試使用以下代碼使用 SSH 和 LibGit2 克隆存儲庫:

#include <string>
#include <iostream>
#include "main.h"
#include "git2.h"

using namespace std;

int creds(git_cred **out, const char *url, const char *username_from_url,
             unsigned int allowed_types, void *payload) {
    cout << "Calling creds" << endl;
    return git_credential_ssh_key_new(out, username_from_url,
            "path_to_home/.ssh/id_rsa.pub", "path_to_home/.ssh/id_rsa", "password");
}

int main() {
    git_libgit2_init();
    string url = "git@github.com:Black-Photon/Git-Testing.git";

    git_repository *repo = nullptr;
    git_clone_options ops = GIT_CLONE_OPTIONS_INIT;
    ops.fetch_opts.callbacks.credentials = creds;

    int err = git_clone(&repo, url.c_str(), "path_to_home/Documents/temp/Git-Testing", &ops);
    cout << giterr_last()->message << endl;

    git_libgit2_shutdown();
}

但是我得到的 output 是:

Calling creds
Calling creds
Calling creds
...

建議它不接受 SSH 密鑰和密碼。 但是,當我在普通 Git 中使用相同的密鑰和密碼時:

git clone git@github.com:Black-Photon/Git-Testing.git
Cloning into 'Git-Testing'...
Enter passphrase for key 'path_to_home/.ssh/id_rsa': password
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 29 (delta 0), reused 13 (delta 0), pack-reused 6
Receiving objects: 100% (29/29), 4.58 KiB | 426.00 KiB/s, done.

它工作正常。 為什么使用 LibGit2 失敗?

我正在使用 LibGit2 版本 0.99.0。 我已經嘗試在id_rsa中保留和刪除空的最后一行,之前在 LibGit2 版本 0.26.0 上給出了不同的消息: Failed to authenticate SSH session: Callback returned error 我也嘗試使用git_credential_ssh_key_memory_new得到相同的結果。

正在使用的 SSH 庫,1.8.0 已經過時,必須更新到 1.9.0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM