PHP ssh2_auth_pubkey_file回调返回错误

时间:2019-03-01 14:19:07

标签: php key sftp

我写了这段代码:

$host = <My Host>;
$port = 22;
$methods = array('hostkey', 'ssh-rsa');
$username = <My User>;
$pub_key = 'c:\\Users\\MyUser\\AppData\\Roaming\\ssh\\UserKeys\\pub_key.pub';
$prv_key = 'c:\\Users\\MyUser\\AppData\\Roaming\\ssh\\UserKeys\\prv_key';

print "<pre>";
var_export(file_get_contents($pub_key));
print "</pre>";
print "<pre>";
var_export(file_get_contents($prv_key));
print "</pre>";

$connection = ssh2_connect($host, 22, $methods); 
if(ssh2_auth_pubkey_file($connection, $username, $pub_key, $prv_key)){
    echo "Ok!!!!\n";
}else{
    echo "Ko!!!!";
}

运行代码时,它将返回:

  

警告:ssh2_auth_pubkey_file():身份验证失败   使用公共密钥:回调返回错误。...

有人可以帮我解决这个问题吗?

0 个答案:

没有答案