1

I have some project to do but killing myself and cannot do anything, i need you help . I am have to make PHP Command to use SSH Connection. I am using Putty , entering IP and Port, than browsing .PPK file ( key authentication file ) and Entering Username And Password, after using command Reboot . so server is rebooting.

Now i want to make all of this simply using PHP , i want to make a textbox and submit button , when entering IP address in textbox and clicking submit button it should make all this reboot command in background. (port is default 22). I will make this textboxes and buttons but cannot get how to make this connection with command and key authentication. if somebody know this please help me solving this problem. i cannot take it any more.

1

1 Answer 1

1

You must use phpseclib.

  • Download it from here or here ( direct link ) .

  • Include it to your project.

And then :

include('Net/SSH2.php');
$ssh = new Net_SSH2('www.example.com');
$ssh->login('username', 'password') or die("Login failed");
// $ssh->getServerPublicHostKey(); if this is your first time connecting
// check $ssh->getServerPublicHostKey() against previously saved 
//                                value on subsequent connections
echo $ssh->exec('reboot');
Sign up to request clarification or add additional context in comments.

10 Comments

I have donwloaded PHPseclib from your link and uploaded on server . after created index.php with code : include('Net/SSH2.php'); $ssh = new Net_SSH2('IP address', 22); $ssh->login('myusername', 'mypass') or die("Login failed"); echo $ssh->exec('reboot'); after what to do it says login Failed . WHere i have to give Key File?
did you tried $ssh = new Net_SSH2('IP address'); without port number ?
not yet but i cannot understand where i have to put my PPK key file for authentication, without key auth it's not logging
what do you mean without key auth it's not logging, I dont think its necessary here .
You load the key by doing $rsa = new Crypt_RSA(); $rsa->loadKey(file_get_contents('/path/to/key.ppk')); $ssh->login('username', $key);
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.