【问题标题】:ssh connection not working in phpssh连接在php中不起作用
【发布时间】:2016-10-01 21:38:03
【问题描述】:

使用腻子我可以连接。但是使用 PHP 我不能。我不知道,为什么会这样?我在 PHP 中安装并启用了扩展 ssh2。

我使用了以下代码:-

$ssh2 = ssh2_connect('myhost');
if (false === $ssh2) {
 die('connection failed');
}
$auth = @ssh2_auth_password($ssh, "hostusername", "hostpassword");
if (false === $auth) {
  die('authentication failed');
}
echo ssh2_exec($ssh2,'pwd');

但这会出现以下错误: 警告:ssh2_exec():连接未通过身份验证

【问题讨论】:

    标签: php linux ssh


    【解决方案1】:

    你有一个错字。您的 SSH 身份验证适用于 $ssh 而不是 $ssh2。 (第 5 行)

    【讨论】:

      【解决方案2】:

      你有 $ssh 的类型,而不是 $ssh2 第 5 行。

      您的代码必须是

      $ssh2 = ssh2_connect('myhost');
      if (false === $ssh2) {
       die('connection failed');
      }
      $auth = @ssh2_auth_password($ssh2, "hostusername", "hostpassword");
      if (false === $auth) {
        die('authentication failed');
      }
      echo ssh2_exec($ssh2,'pwd');
      

      【讨论】:

        猜你喜欢
        • 2021-01-10
        • 2015-08-13
        • 2017-12-19
        • 2014-06-17
        • 2019-03-09
        • 2014-11-29
        • 2013-05-30
        • 2018-11-30
        相关资源
        最近更新 更多