【问题标题】:How do I set ssh credentials for libgit2/libssh2?如何为 libgit2/libssh2 设置 ssh 凭据?
【发布时间】:2014-01-06 18:39:21
【问题描述】:

我正在尝试从pygit2/libgit2 中推送引用:

    push_refspec = git_repo.lookup_reference('HEAD').resolve().name
    logger.info("Pushing " + push_refspec)
    git_remote.push(push_refspec)

但是,我收到有关缺少凭据的错误:

    _pygit2.GitError: Cannot set up SSH connection without credentials

这最终来自libssh2,来自libgit2 (transports/ssh.c) 的调用:

if (user && pass) {
    if (git_cred_userpass_plaintext_new(&t->cred, user, pass) < 0)
        goto on_error;
} else if (t->owner->cred_acquire_cb) {
    if (t->owner->cred_acquire_cb(
            &t->cred, t->owner->url, user,
            GIT_CREDTYPE_USERPASS_PLAINTEXT |
            GIT_CREDTYPE_SSH_KEY |
            GIT_CREDTYPE_SSH_CUSTOM,
            t->owner->cred_acquire_payload) < 0)
        goto on_error;

    if (!t->cred) {
        giterr_set(GITERR_SSH, "Callback failed to initialize SSH credentials");
        goto on_error;
    }
} else {
    giterr_set(GITERR_SSH, "Cannot set up SSH connection without credentials");
    goto on_error;
}

使用 Git 客户端来自存储库的 push 工作正常。我试过GIT_SSL_NO_VERIFY=true(不出所料)没有用。

我需要设置哪些额外信息才能使其正常工作?

【问题讨论】:

    标签: git libgit2 libssh2 pygit2


    【解决方案1】:

    看起来 pygit2 还不支持 libgit2 的凭据网络操作。有some API discussion happening,但没有最终确定。

    编辑:自从这个答案被接受以来,这似乎已经实现了。 documentation 对此有一些注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 2017-10-15
      • 2011-09-23
      • 2017-04-13
      • 1970-01-01
      • 2014-04-17
      相关资源
      最近更新 更多