Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使用libgit2连接到专用github存储库_Macos_Authentication_Github_Ssh_Libgit2 - Fatal编程技术网

Macos 使用libgit2连接到专用github存储库

Macos 使用libgit2连接到专用github存储库,macos,authentication,github,ssh,libgit2,Macos,Authentication,Github,Ssh,Libgit2,我正在尝试使用libgit2获取私有github存储库。回购属于某个组织,我拥有读/写权限。该程序是用Objective-C++编写的。我有这个: - (int)fetchBranches { git_remote *remote = NULL; int result = 0; if (!(result = git_remote_load(&remote, repo, "origin"))) { git_remote_callbacks callb

我正在尝试使用libgit2获取私有github存储库。回购属于某个组织,我拥有读/写权限。该程序是用Objective-C++编写的。我有这个:

- (int)fetchBranches
{
    git_remote *remote = NULL;
    int result = 0;
    if (!(result = git_remote_load(&remote, repo, "origin"))) {
        git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
        callbacks.credentials = cred_acquire_cb;
        git_remote_set_callbacks(remote, &callbacks);
        result = git_remote_fetch(remote);
    }
    return result;
}

int cred_acquire_cb(git_cred **out,
                    const char * url,
                    const char * username_from_url,
                    unsigned int allowed_types,
                    void * payload)
{
    return git_cred_ssh_key_new(out, "GITHUBUSERNAME", "/Users/admin/.ssh/id_rsa.pub", "/Users/admin/.ssh/id_rsa", "PASSPHRASE");
}
这将创建凭据,但当我执行提取操作时,尝试使用libssh2对会话进行身份验证时失败。(libgit2/src/transports/ssh.c:302):

错误为-18,LIBSSH2\u错误\u身份验证\u失败。我已确认公钥已添加到Github,并尝试将其更改为新的公钥。此外,密码短语是正确的,用户名是我的github用户名。我也可以通过控制台抓取。远程配置为:

[remote "origin"]
    url = git@github.com:ORGNAME/REPONAME.git
    fetch = +refs/heads/*:refs/remotes/origin/*
我还尝试从OSX中的git代理获取密钥,结果相同:

return git_cred_ssh_key_from_agent(out, "GITHUBUSERNAME");
最后,我尝试使用明文身份验证:

return git_cred_userpass_plaintext_new(out, username, password);
最后一种方法在将repo url更改为HTTPS地址后工作。问题是,它要求用户每次输入密码,或者将包含密码的git_cred结构存储为空(不喜欢这样)


有人知道ssh身份验证失败的原因吗?有没有一种方法可以避免在每次操作中输入用户名/密码(使用明文身份验证)?

通过ssh交谈的用户是“git”(因此所有URL都是
git@github.com:user/repo
),因此您应该使用该用户名,而不是GitHub上的“真实”用户名。您发送的密钥是服务器用来确定与哪个用户打交道的密钥。

您一直提到“GITHUBUERNAME”,但对于SSH身份验证,SSH用户是“git”。关键是用来计算GitHub用户名的是什么。好吧,我真是太蠢了。是的,用户是git。有了这个,它就开始工作了。如果你想提出一个答案,我会认为它是有效的。谢谢
return git_cred_userpass_plaintext_new(out, username, password);