2

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

Im using php 5.3 on Linux/CEntOS.

What I have done so far :

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

But I'm getting this error :

Fatal error: Call to undefined function ssh2_connect()

So, my questions are :

  1. Are ssh2_* functions not installed by default in php?

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

  3. How can I solve this problem ?

4

3 回答 3

8

您可以配置您的服务器(Ubuntu):

sudo apt-get install libssh2-php
sudo service apache2 restart
于 2015-08-11T17:14:28.733 回答
6

phpseclib

  • 这里这里下载(直接链接),

  • 将其包含到项目中,

接着 :

   include('Net/SSH2.php');
   $ssh = new Net_SSH2('www.example.com');
   $ssh->login('username', 'password') or die("Login failed");
   echo $ssh->exec('command');
于 2014-01-27T20:30:10.200 回答
3

ssh_* 函数并非默认安装在 php 核心中。您必须使用 pecl 添加它们,有关详细说明,请参阅 php 手册:http: //de1.php.net/manual/en/ssh2.installation.php

于 2013-09-14T09:37:38.537 回答