Libgit2 - 无法验证 SSH 会话:无法打开公钥文件
Libgit2 - Failed to authenticate SSH session: Unable to open public key file
我正在尝试使用 ssh 通过 Libgit2 的网络做一个非常简单的 git 克隆 - 在此过程中获得标题中的错误。我不确定我做错了什么 - 这不是网络问题,因为我可以通过命令行克隆存储库。键也位于指定的路径中。
此外,密钥已经设置好,如果我想 ssh 到我尝试克隆的机器,我只需要提供一个密码,所以不确定为什么我需要在这里重新定义它。
#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://username@66.66.66.666/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;
}
在cred_cb
中打印allowed_types
表示22
,因此如果您尝试返回不同类型的git_cred(例如,git_cred_userpass_plaintext
),库会抱怨callback returned unsupported credentials type
,并且如果没有指定回调(通过调用git_clone
以NULL
作为第三个参数),那么它说authentication required but no callback set
。我可能错过了一些明显的东西,我将不胜感激任何帮助,谢谢。
编辑
相反,我尝试使用git_cred_ssh_key_from_agent(out, "username")
它似乎做了一些事情(git 文件夹被克隆),尽管缺少文件。尽管现在的问题是它变成了cred_cb
和git_clone
之间的无限循环(似乎来回调用)。
密钥文件的路径应该是不带 ~ 的完整路径。Libgit2 不会像 shell 那样扩展 ~ 。
此外,密码应该是用于加密私钥的密码,而不是用于向遥控器进行身份验证的密码。
相关文章:
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 将TPM公钥序列化为DER或PEM
- 使用公钥加密消息:BER 解码错误
- 比较两个公钥与OpenSSL API
- 以 x64 配置访问证书公钥
- 使用 char 数组公钥的 OpenSSL 进行 RSA 加密
- 如何获取两个 std::map 的公钥?
- BERDecodeError尝试使用公钥验证签名时出错
- 从字符串 Crypto++ 导入 RSA 公钥/私钥
- 使用 gpgme 在 c++ 中导出 gpg 公钥
- 如何在C++中将 JWK 公钥转换为 PEM 格式
- 打印私人/公钥
- 一代 RSA-2048 密钥(公钥和私钥)
- RSA公共加密使用X509证书C 的公钥
- 在 SSH 上的公钥-私钥身份验证上的 libcurl 实现
- 使用 WinHttpQueryOption 获取公钥的大小
- 使用公钥 X509 V3 (PKCS7) 使用 AES 128 模式 cbc 加密文件
- Libgit2 - 无法验证 SSH 会话:无法打开公钥文件
- 使用Crypto++库仅从x压缩坐标检索ECDSA公钥
- 在 GnuPG 中从 C/C++ 和参数生成公钥/私钥