教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP安装ssh2扩展

PHP安装ssh2扩展

发布时间:2020-10-26   编辑:jiaochengji.com
教程集为您提供PHP安装ssh2扩展等资源,欢迎您收藏本站,我们将为您提供最新的PHP安装ssh2扩展资源
安装

下载包

$ 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安装ssh2扩展的详细内容,更多请关注教程集其它相关文章!

  • 本文转载于:segmentfault,如有侵犯,请联系jquerycn@qq.com删除
  • 您可能感兴趣的文章:
    php连接服务器进行服务器命令操作
    PHP安装ssh2扩展
    php远程copy与执行命令的实例分享
    OneinStack 安装 PHP 扩展
    php添加imagick扩展的方法
    Linux系统下配置SSH方法
    php实例之检测可用的mysql扩展类型
    linux下 php 安装xml扩展的方法
    CentOS 6上安装php-mcrypt扩展的方法
    php扩展安装不生效

    [关闭]
    ~ ~