使用 PHP SSH 连接到远程服务器 [英] SSH Connection to a remote server using PHP

查看:71
本文介绍了使用 PHP SSH 连接到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 php 与远程服务器建立 SSH 连接.

I want to make a SSH connection to a remote server using php.

我在 Linux/CEntOS 上使用 php 5.3.

Im using php 5.3 on Linux/CEntOS.

到目前为止我所做的:

$connection = ssh2_connect('192.168.1.22', 22);
ssh2_auth_password($connection, '_username', '_password');
$stream = ssh2_exec($connection, 'ls -l');

但我收到此错误:

致命错误:调用未定义的函数 ssh2_connect()

所以,我的问题是:

  1. php默认没有安装ssh2_*函数吗?

我是否需要扩展或库来使用这些函数?

Do I need an extension or library for using these functions?

我该如何解决这个问题?

How can I solve this problem ?

推荐答案

phpseclib

  • 此处这里(直接链接),

    phpseclib

    • Download it from here or here ( direct link ) ,

      将其添加到项目中,

      然后:

         include('Net/SSH2.php');
         $ssh = new Net_SSH2('www.example.com');
         $ssh->login('username', 'password') or die("Login failed");
         echo $ssh->exec('command');
      

      这篇关于使用 PHP SSH 连接到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆