$ wget http://www.libssh2.org/download/libssh2-1.4.2.tar.gz
php
$ wget http://pecl.php.net/get/ssh2-0.12.tgz
ssh
$ tar -zxvf libssh2-1.4.2.tar.gz
.net
$ cd libssh2-1.4.2
調試
$ ./configure --prefix=/usr/local/libssh2
code
$ make && make install
get
$ tar -zxvf ssh2-0.12.tgz
cmd
$ cd ssh2-0.12
it
$ /usr/local/zend/bin/phpize
io
$ ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2 --with-php-config=/usr/local/zend/bin/php-config
編譯
$ make && make install
修改php.ini 加入
extension=ssh2.so
重啓PHP
$user="root";//遠程用戶名 $pass="******";//遠程密碼 $connection=ssh2_connect('10.10.10.10',22); ssh2_auth_password($connection,$user,$pass);
$connection=ssh2_connect('10.10.10.10',22); if(ssh2_auth_pubkey_file($connection, 'root', '/home/id_rsa.pub', '/home/id_rsa', 'secret')) { echo "Public Key Authentication Successful\n"; } else { die('Public Key Authentication Failed'); }
$cmd="ps aux";//命令 $ret=ssh2_exec($connection,$cmd); stream_set_blocking($ret, true); echo (stream_get_contents($ret));