LibGit2 SSH身份验证失败

问题描述 投票:1回答:1

我正在尝试使用带有以下代码的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 = "[email protected]: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();
}

但是我得到的输出是:

Calling creds
Calling creds
Calling creds
...

建议它不接受SSH密钥和密码。但是,当我在普通的Git中使用相同的密钥和密码时:

git clone [email protected]: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中保留和删除空的最后一行,并且以前在0.26.0的LibGit2版本中给出了不同的消息:Failed to authenticate SSH session: Callback returned error。我也尝试过使用 git_credential_ssh_key_memory_new获得相同的结果。

c++ ssh libgit2
1个回答
0
投票

正在使用的SSH库1.8.0已过时,必须更新为1.9.0。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.