私は非常に単純な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_types
は22
を言うと、あなたが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_cb
とgit_clone
の間の無限ループになります(前後に呼ばれるようです)。