PHP安装ssh2扩展-php教程

资源魔 25 0
装置

下载包

$ wget http://www.libssh2.org/download/libssh2-1.4.2.tar.gz
$ wget http://pecl.php.net/get/ssh2-0.12.tgz

先装置 libssh2 再装置 SSH2

$ tar -zxvf libssh2-1.4.2.tar.gz
$ cd libssh2-1.4.2
$ ./configure --prefix=/usr/local/libssh2
$ make && make install

编译装置ssh2

$ tar -zxvf ssh2-0.12.tgz
$ cd ssh2-0.12
$ /usr/local/zend/bin/phpize
$ ./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);

用sshkey形式登录

$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));

更多的PHP相干常识,请拜访PHP中文网!

以上就是PHP装置ssh2扩大的具体内容,更多请存眷资源魔其它相干文章!

标签: php php开发教程 php开发资料 php开发自学

抱歉,评论功能暂时关闭!