ssh2_auth_none返回true

时间:2012-11-14 19:05:49

标签: php ssh cisco

我有一个场景,当我呼叫ssh2_auth_none时,它会返回true。根据文档,它似乎表明这意味着交换机配置为允许登录而无需身份验证。

但事实并非如此。我们正在使用密码......

以下是我的代码:

<?php
$connection = ssh2_connect('10.124.123.45', 22);

$auth_methods = ssh2_auth_none($connection, 'username');
var_dump($auth_methods);

if (in_array('password', $auth_methods)) {
       echo "Server supports password based authentication\n";
}
?>

只是想知道您对我可以测试或检查以解决此问题的任何想法或意见。最后,我希望能够致电ssh2_connectssh2_auth_password()来登录此交换机。

感谢。

1 个答案:

答案 0 :(得分:0)

我们不得不改变连接到这些类型交换机的方式 - 问题的根本原因是此交换机的ssh实现非常有限,因此像phpseclib这样的流行库不起作用。

这是我们的代码可行 - 如果它帮助那些试图连接到CISCO的小型企业级交换机的其他人。

  <?php
      $uname = 'myusername';
      $pswd = 'mypassword';
      $connection = ssh2_connect('123.123.123.123', 22);
      //$authentication_methods = ssh2_auth_none($connection, 'user');
      $stdio_stream = ssh2_shell($connection);
      fwrite($stdio_stream,$uname."\n");
      sleep(1);
      fwrite($stdio_stream,$pswd."\n");
      sleep(1);
      echo "Results: " . stream_get_contents($stdio_stream); 
      echo 'sending show bonjour command:<br>';
     fwrite($stdio_stream, "show bonjour".PHP_EOL);
     sleep(1);
     echo "<br>Results: " . stream_get_contents($stdio_stream); 
  ?>