Jump to content

Help with SSH2 functions and general use (not installation)


aluminumpork

Recommended Posts

I finally got the SSH2 PHP extension installed and working properly and have played around with some of the functions and also a couple of classes that simply things. However, I guess I'm still a bit confused as to how to connect to your standard fare Linux box and actually get something done.

 

For instance, most of the SSH2 classes wrap the ssh2_connect and ssh2_auth_password functions together, so you can do something like this:

 

$ssh->connect($host, $user, $pass, $port);

 

However, this always fails with an authentication failed message, even though I -know- the information I provided is correct. I'm kind of at a loss as to where to go from here.

My ultimate goal is to be able to connect, run a command, retrieve the results of the command and disconnect, which I have been able to do with a telnet class in PHP, without much issue. Due to the insecurity of Telnet however, I do not want to continue using it.

 

Any help is greatly appreciated. Thanks.

Link to comment
Share on other sites

  • 6 months later...

Have you tried NOT wrapping them to see what you get?

 

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");

// log in at server1.example.com on port 22

if(!($con = ssh2_connect("server1.example.com", 22))){

    echo "fail: unable to establish connection\n";

} else {

    // try to authenticate with username root, password secretpassword

    if(!ssh2_auth_password($con, "root", "secretpassword")) {

        echo "fail: unable to authenticate\n";

    } else {

        // allright, we're in!

        echo "okay: logged in...\n";

      }

    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.