我正在尝试从 RHEL SSH 到 SLES 机器。我正在使用 PHP 函数 ssh2 来实现这一点。即使通过正确的用户名和密码,身份验证也不会发生。但是相同的代码在 RHEL->RHEL 上运行良好。我可以从 RHEL 终端 ssh 到 SLES 机器。但是使用 ssh2 并没有发生。
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at ip on port 22
if(!($con = ssh2_connect(ip, 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password password
if(!ssh2_auth_password($con, "root", "password")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, 'date' ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
//echo "in else";
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
echo $data;
fclose($stream);
}
}
}
?>
我得到输出“失败:无法验证”。为什么会这样?有什么解决办法吗?