首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LibGit2 SSH授权失败

LibGit2 SSH授权失败
EN

Stack Overflow用户
提问于 2020-02-23 16:14:31
回答 1查看 365关注 0票数 2

我试图使用LibGit2使用以下代码克隆存储库:

代码语言:javascript
复制
#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();
}

但是,我得到的输出是:

代码语言:javascript
复制
Calling creds
Calling creds
Calling creds
...

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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-18 19:31:25

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60364214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档