Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh connection not working in php

Tags:

linux

php

ssh

Using putty I can able to connect. But using PHP I can't. I don't know ,why it is happening? I installed and enabled the extension ssh2 in PHP.

I used the following Code:-

$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');

But this will the following error: Warning: ssh2_exec(): Connection not authenticated

like image 269
Bro Avatar asked Mar 03 '26 14:03

Bro


1 Answers

You have a typo. Your SSH authentication is for $ssh not for $ssh2. (line 5)

like image 65
Dentastic Avatar answered Mar 06 '26 03:03

Dentastic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!