Code below works, it perfectly returns the user name that I connected with to the SSH server. Is it possible to create some sort of interactive shell where I can send the commands myself. Just like a black terminal window on a Mac for example. I've seen some documentation on the ssh2_shell function where you can specify the width and height of the terminal window, but cannot get that working.
$server['ip'] = "127.0.0.1";
$server['sshport'] = 22;
$server['user'] = "myUsername";
$server['pw'] = "myPassword!";
$command = "whoami";
if($ssh = ssh2_connect($server['ip'], $server['sshport'])) {
if(ssh2_auth_password($ssh, $server['user'], $server['pw'])) {
$stream = ssh2_exec($ssh, $command);
stream_set_blocking($stream, true);
$data = "";
while($buffer = fread($stream, 4096)) {
$data .= $buffer;
}
fclose($stream);
print $data;
} else {
echo "User or password is incorrect!";
}
} else {
echo "Could not connect to the ssh server!";
}