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');
 
$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('username@username:~$');
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
?>

+ Download Source Code phpseclib And Demo + 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, 2012 Hoan 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 hoan@4rapiddev.com

7 years ago PHPphpseclib, SSH525
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
18,697 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
14,446 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
13,326 views
JQuery Allow only numeric characters or only alphabet characters in textbox
10,871 views
C# Read Json From URL And Parse/Deserialize Json
7,461 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
  • Magento Fatal error: Unsupported operand types
  • Ionic bower the name contains uppercase letters
  • PHP Magento Get Manufacturer Name And ID From Magento Product ID
  • Know Simple Hacks To Systematize Media Library in WordPress
  • A handy guideline on adding custom menu item in WordPress admin
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (26)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (140)
EMAIL SUBSCRIPTION

Sign up for our newsletter to receive the latest news and event postings.

Recommended
  • CDN
  • Hosting
  • Premium Themes
  • VPS
2014 © 4 Rapid Development