PHP安装ssh2扩展的步骤

发布时间:2020-07-02 15:43:34 作者:Leah
来源:亿速云 阅读:148

这篇文章将为大家详细讲解有关PHP安装ssh2扩展的步骤,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

安装

下载包

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

先安装 libssh3 再安装 SSH2

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

编译安装ssh3

$ tar -zxvf ssh3-0.12.tgz
$ cd ssh3-0.12
$ /usr/local/zend/bin/phpize
$ ./configure --prefix=/usr/local/ssh3 --with-ssh3=/usr/local/libssh3 --with-php-config=/usr/local/zend/bin/php-config
$ make && make install

修改php.ini 加入

extension=ssh3.so

重启PHP

调试

用户名密码方式登录

$user="root";//远程用户名
$pass="******";//远程密码
$connection=ssh3_connect('10.10.10.10',22);
ssh3_auth_password($connection,$user,$pass);

用sshkey方式登录

$connection=ssh3_connect('10.10.10.10',22);
if(ssh3_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=ssh3_exec($connection,$cmd);
stream_set_blocking($ret, true);
echo (stream_get_contents($ret));

关于PHP安装ssh2扩展的步骤就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. ubuntu 环境下安装php的ssh2扩展
  2. php安装phalcon扩展的步骤

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php ssh2扩展

上一篇:Vue.js计算属性

下一篇:linux设置root权限的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》