我正在try 通过php curl连接到SFTP目的地,并使用密钥身份验证.
我设法连接到cURL之外,使用了Open SSH:(它起作用了)
sftp -i myPrivateKey sftp://myusername@destination.com
但是,我不能在cURL中重现这个连接,我有一个身份验证失败错误.那件事怎么可能?
$dest = 'sftp://myusername@mydestination:22';
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_URL, $dest);
curl_setopt($curlHandler, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curlHandler, CURLOPT_VERBOSE, true);
curl_setopt($curlHandler, CURLOPT_SSH_PUBLIC_KEYFILE, mypublickey);
curl_setopt($curlHandler, CURLOPT_SSH_PRIVATE_KEYFILE,myprivatekey);
$resp = curl_exec($curlHandler);
以下是以下内容:
* SSH public key authentication failed: Callback returned error
* Failure connecting to agent
* Authentication failure
* Closing connection 0
我确信密钥的有效性,我与远程服务器判断了 fingerprint ,并设法连接到了php-curl之外.
我还判断了我的 keys 是否处于受限访问和可访问状态