• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP安装ssh2扩展

php 搞代码 4年前 (2022-01-20) 18次浏览 已收录 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 -zx<i style="color:transparent">本#文来源gaodai$ma#com搞$$代**码网$</i><button>搞代gaodaima码</button>vf 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扩展的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP安装ssh2扩展

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址