cURL sftp公钥认证失败“回调错误” [英] cURL sftp public key authentication fails "Callback Error"

查看:1166
本文介绍了cURL sftp公钥认证失败“回调错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些php代码工作上传文件使用cURL到主机,只是使用用户&密码ftp,现在我必须上传到只允许公共密钥验证的服务器,并得到错误:* SSH公共密钥身份验证失败:回调返回错误

I have some php code which works well uploading files using cURL to hosts which are simply using user & password ftp, now I have to upload to a server which only allows public key auth and am getting the error: "* SSH public key authentication failed: Callback returned error"

我有一个问题,因为他们不是正确的格式,但已经把它们放在正确的单行格式,这停止了不base64编码的错误。我在这个回调错误在网上找不到很多帮助。

I had a problem with the keys as they were not in the right format, but have since put them in the correct single line format and this stopped the "not base64 encoded" errors. I can't find much help on this callback error online.

我的代码如下。

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); 
curl_setopt($ch, CURLOPT_URL, 'sftp://user:@12.12.12.12:22/testfile.gz');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE,'C:\keys\public.pub');
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE,'C:\keys\private.ppk');
curl_setopt($ch, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,'2acfe24108c37a276a93ac3398a5oe8f');
curl_setopt($ch, CURLOPT_SSH_AUTH_TYPES,CURLSSH_AUTH_PUBLICKEY);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
$sR = curl_exec ($ch);

这里是运行测试的输出

* About to connect() to 12.12.12.12 port 22 (#0)
*   Trying 12.12.12.12...
* connected
* Connected to 12.12.12.12 (12.12.12.12) port 22 (#0)
* SSH MD5 fingerprint: ebbc61b886c798b25073c912833ffers
* SSH authentication methods available: publickey
* Using ssh public key file C:\keys\public.pub
* Using ssh private key file C:\keys\private.ppk
* SSH public key authentication failed: Callback returned error
* Authentication failure
* Closing connection #0

任何帮助。

推荐答案

当你的libssh2是用libgcrypt构建时,有一些情况(基于debian的发行版)。
在其中,使用PEM编码的私钥文件:

There are cases (debian-based distros) when your libssh2 is built with libgcrypt. In those, use PEM-encoded private key file:

$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem

这篇关于cURL sftp公钥认证失败“回调错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆