溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PHP安裝ssh2擴展的步驟

發(fā)布時間:2020-07-02 15:43:34 來源:億速云 閱讀:155 作者:Leah 欄目:編程語言

這篇文章將為大家詳細講解有關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');
}

執(zhí)行命令獲取返回值

$cmd="ps aux";//命令
$ret=ssh3_exec($connection,$cmd);
stream_set_blocking($ret, true);
echo (stream_get_contents($ret));

關于PHP安裝ssh2擴展的步驟就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI