I am trying to ssh from RHEL to SLES machine. I am using PHP function ssh2 to achieve that. Authentication is not happening even after passing correct username and password. But the same code is working fine for RHEL->RHEL. I am able to ssh to the SLES machine from RHEL terminal. But using ssh2 it is not happening.
<?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);
}
}
}
?>
I am getting the output "fail:unable to authenticate". Why is it happening that way? Any solution to it?