![](/img/trans.png)
[英]Supply PHP function ssh2_auth_pubkey_file with private key as string, not a file
[英]PHP ssh2_auth_pubkey_file not working with encrypted private key
我在PHP中使用ssh2,如下所示:
$connection = ssh2_connect($host, $port);
ssh2_auth_pubkey_file($connection, $username, $pubKey, $privKey, $passphrase);
這將導致錯誤消息:
ssh2_auth_pubkey_file(): Authentication failed for username using public key
但是,我可以直接在終端中使用sftp進行正常連接。
$ sftp -oPort=PORT -i /path/to/private/key USER@HOST
(sftp命令響應,要求輸入密碼,然后連接。)
我對此調試感到有些茫然-ssh2命令要求並提供所有相關信息來進行連接,並且我可以直接在終端中使用sftp進行連接。 可能是什么問題?
我最終放棄了phpseclib的 ssh2。
首先,按以下方式加載私鑰:
$key = new Crypt_RSA();
$key->setPassword($passphrase);
$key->loadKey(file_get_contents($keyPath));
然后使用密鑰登錄:
$sftp = new Net_SFTP($host, $port);
$loginResult = $sftp->login($username, $key);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.