2017-02-23 14 views
1

私は非常に単純なgitクローンをLibgit2のネットワーク上でsshを使って実行しようとしています。私は何が間違っているのかよくわかりません。ネットワーク上の問題ではなく、コマンドラインからリポジトリをクローンすることができます。キーは指定されたパスにもあります。Libgit2 - SSHセッションの認証に失敗しました:公開鍵ファイルを開くことができません

また、私がマシンにssh接続したいのであれば、私はクローンを作成しようとしています。パスワードを入力する必要があるので、なぜここでそれを再定義する必要があるのか​​分かりません。 cred_cb

#include <git2.h> 
#include <iostream> 

// Callback function 
int cred_cb(git_cred **out, const char *url, const char *username_from_url, 
    unsigned int allowed_types, void *payload) { 

    // https://libgit2.github.com/libgit2/#HEAD/group/cred/git_cred_ssh_key_new 
    return git_cred_ssh_key_new(out, "username", 
     "~/.ssh/id_rsa.pub", "~/.ssh/id_rsa", "password"); 
} 

int main() { 
    // Start up libgit2 
    git_libgit2_init(); 

    // Test clone setup 
    git_repository *repo = NULL; 
    const char *url = "ssh://[email protected]/home/git_repo_to_clone"; 
    const char *path = "tmp"; 

    // Test clone 
    git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; 
    clone_opts.fetch_opts.callbacks.credentials = cred_cb; 
    int error = git_clone(&repo, url, path, &clone_opts); 

    // Prints the last error message 
    std::cout << giterr_last()->message << std::endl; 

    // Clean up 
    git_libgit2_shutdown(); 

    return 0; 
} 

印刷allowed_types22を言うと、あなたがgit_credの異なるタイプを返すようにしようとした場合ので(例えば、git_cred_userpass_plaintext)ライブラリはcallback returned unsupported credentials typeと文句を言い、また、コールバックがでgit_cloneを呼び出すことによって、(指定されていない場合第3のパラメータとしてNULL)、それはauthentication required but no callback setと言います。私は明白な何かを見逃しているかもしれない、私は、感謝する任意の助け、ありがとう。

は編集

私の代わりにgit_cred_ssh_key_from_agent(out, "username")にしようと、不足しているファイルとはいえ、(gitのフォルダがクローン化されます)何かをやっているようです。今問題は、cred_cbgit_cloneの間の無限ループになります(前後に呼ばれるようです)。

答えて

1

キーファイルへのパスは〜のない完全パスにする必要があります。 Libgit2はシェルのように〜は展開しません。

また、パスワードは、リモートでの認証に使用するパスワードではなく、秘密鍵の暗号化に使用するパスフレーズである必要があります。

関連する問題