Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP SSH To Remote Server And Execute Command

PHP SSH To Remote Server And Execute Command

There is a PHP library called phpseclib that helps to SSH to a remote server and execute command. We can also get the output and display on the screen.

First, we need to download the phpseclib, it’s available to download via: http://phpseclib.sourceforge.net/

Examples SSH To Remote Server And Execute Command With PHP

<?php
include('Net/SSH2.php');
 
$ssh = new Net_SSH2('domain.com');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}
 
echo $ssh->exec('ls');
?>

<?php include('Net/SSH2.php'); $ssh = new Net_SSH2('domain.com'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('ls'); ?>

<?php
include('Net/SSH2.php');
 
$key = new Crypt_RSA();
//$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
 
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', $key)) {
    exit('Login Failed');
}
 
echo $ssh->read('[email protected]:~$');
$ssh->write("ls -la\n");
echo $ssh->read('[email protected]:~$');
?>

<?php include('Net/SSH2.php'); $key = new Crypt_RSA(); //$key->setPassword('whatever'); $key->loadKey(file_get_contents('privatekey')); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', $key)) { exit('Login Failed'); } echo $ssh->read('[email protected]:~$'); $ssh->write("ls -la\n"); echo $ssh->read('[email protected]:~$'); ?>

+ [download id=”20″ format=”1″] + View our demonstration page to see how it works.

PHP SSH To Remote Server And Execute Command

PHP SSH To Remote Server And Execute Command

Mar 10, 2012Hoan Huynh

Source Code Demo page

Display Site Down Or Maintenance Message In ASP.NET Web ApplicationIE How to view your saved passwords
You Might Also Like:
  • How To Enable Telnet Command In Windows 7 And Server 2008
  • Export/Import Data From Local Database To Remote Database With MS SQL Server 2008
  • Save Table Structure Changes When Remote Access To SQL Server
  • PHP Connect To MS SQL Server
  • How To Filter DataBase Name And Login Username In SQL Server Profiler
  • PHP Get Remote File Size And Content Type
  • centos -bash pecl command not found
  • PHP Get Remote Image Width Height
  • ASP.NET Store Session In MS SQL Server Database
  • Add WordPress Login Form On Sidebar Or Custom Page
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPphpseclib, SSH619
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
21,956 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,804 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,628 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,136 views
C# Read Json From URL And Parse/Deserialize Json
9,594 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Essay Writers
  • College Essay Writers – The Way to Earn Your Essay in Demand
  • Buy Research Papers – How to See Them at a Bargain Price
  • How to Write a Research Paper For Sale
  • Essay Writing – Some Useful Suggestions for Writing Urgent Essays
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (69)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development