PHP ssh2 implement remote upload, download, execute command

Source: Internet
Author: User
Tags ssh

PHP remote Copy and execute command

PHP Remote copy files and when executing commands on a remote server, the module used is SSH2, and all subsequent operations are done according to the SSH2 connection handle.

1. SSH2 Module Installation 1.1 installation required expansion pack

[plain] view plain copy print?  wget http://www.libssh2.org/download/libssh2-1.4.2.tar.gz tar zxf libssh2-1.4.2.tar.gz cd libssh2-1.4.2./configure && make && make install

[plain] view plain copy print? wget http://pecl.php.net/get/ssh2-0.11.3.tgz CD ssh2-0.11.3 phpize (if the error command is not found, apt-get install). Php5-dev Ure-with-ssh2 && make && make install

can be installed directly under Ubuntu : [plain] view plain copy print? Apt-get Install Libssh2-1-dev libssh2-php
Using the direct installation method, you do not need to modify the PHP configuration information.
Ps:

1. Login to remote host:

localhost$ ssh-l jsmith remotehost

2. Connected Remote host:

remotehost$

3. To temporarily return to the local host, enter the exit symbol: "~" and "control-z" combination.

When you type "~" You will not see it immediately on the screen, when you press <Control-Z> and press ENTER to display together. as follows, enter "~<control-z>" on the remote host
1.2 Modify PHP configuration information

[plain] view plain copy print? cd/etc/php5/cgi vim php.ini Add: extension=/usr/lib/php5/20090626/ssh2.so ssh2.so is the module that is obtained when compiling SSH2, which is the location of the module.

[plain] view plain copy print?   CD/ETC/PHP5/CLI vim php.ini Add: extension=/usr/lib/php5/20090626/ssh2.so ssh2.so is the module that is obtained when compiling SSH2, which is the location of the module. 1.3 Restart the Web server

[plain] view plain copy print? /ETC/INIT.D/LIGHTTPD Restart 1.4 to see if the SSH2 is loaded

[plain] view plain copy print? [Root@localhost ~]php-m | grep ssh2 ssh2 2. Connection application of SSH2 module

There are two ways to connect SSH2, namely username password, SSH key form. 2.1 User name and password [PHP] view plain copy print?   $connection = Ssh2_connect ("192.168.6.222", 22);   if (Ssh2_auth_password ($connection, "Veno", "Ubuntu")) {echo "Authentication successful!";   }else{die ("Authentication Failed ..."); } 2.2 ssh key

[PHP]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.