3

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

You have type for $ssh, not $ssh2 Line 5.

Your code must be

$ssh2 = ssh2_connect('myhost');
if (false === $ssh2) {
 die('connection failed');
}
$auth = @ssh2_auth_password($ssh2, "hostusername", "hostpassword");
if (false === $auth) {
  die('authentication failed');
}
echo ssh2_exec($ssh2,'pwd');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.