public 上的 libcurl 实现-SSH 上的私钥身份验证
libcurl implementation on public-private key authentication on SSH
- 已创建 public 和私钥
- ssh-keygen -t rsa <-- 在 SSH 客户端执行操作
- ssh-copy-id @
注意:创建密钥时没有密码
谁能帮我看看如何使用 libcurl PutFile 方法
- 用户名
- 私钥
- public 键
- sftp
试图浏览 libcurl 示例,但遗憾的是这是最相似的示例 https://curl.haxx.se/libcurl/c/usercertinmem.html
忘记 usercertinmem.c,只需要 fileupload.c 并根据需要添加 SSH 选项。
像这样:
curl_easy_setopt(curl, CURLOPT_URL, "sftp://username@host/path/file");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_size);
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, pubkey_filename);
curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, privkey_filename);
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "");
curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, known_host_sign);
res = curl_easy_perform(curl);
您可以在 options documentation 中阅读这些特定于 SSH 的选项和其他选项。
而不是 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
you can also use CURLOPT_SSH_KNOWNHOSTS
or CURLOPT_SSH_KEYFUNCTION
。
- 已创建 public 和私钥
- ssh-keygen -t rsa <-- 在 SSH 客户端执行操作
- ssh-copy-id @ 注意:创建密钥时没有密码
谁能帮我看看如何使用 libcurl PutFile 方法 - 用户名 - 私钥 - public 键 - sftp
试图浏览 libcurl 示例,但遗憾的是这是最相似的示例 https://curl.haxx.se/libcurl/c/usercertinmem.html
忘记 usercertinmem.c,只需要 fileupload.c 并根据需要添加 SSH 选项。
像这样:
curl_easy_setopt(curl, CURLOPT_URL, "sftp://username@host/path/file");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_size);
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, pubkey_filename);
curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, privkey_filename);
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "");
curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, known_host_sign);
res = curl_easy_perform(curl);
您可以在 options documentation 中阅读这些特定于 SSH 的选项和其他选项。
而不是 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
you can also use CURLOPT_SSH_KNOWNHOSTS
or CURLOPT_SSH_KEYFUNCTION
。