PHP code example of wengheng / php-ssh-client

1. Go to this page and download the library: Download wengheng/php-ssh-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wengheng / php-ssh-client example snippets



use SSH_Client;
$host = '101.0.0.1';//ssh host
$port = 22;//ssh端口
$username = 'root';//登录用户名
/*
当$auth_mode为pwd时传入 登录密码,
登录模式为crt时 传入数组
[
'pub_cert'=>'./public_key.crt',
'priv_cert'=>'./private_key.crt',
'cert_pwd'=>''
]
证书路径:pub_cert为公钥,priv_cert为私钥,cert_pwd为证书密码。
*/
$auth_info = '123456';//登录信息见上面说明
$auth_mode = 'pwd';//登录模式 证书登录使用crt 默认使用pwd 密码登录

$ssh_client = new SSH_Client\Client($host, $username, $auth_info, $port, $auth_mode);
$cmd = 'ls';

$res = $ssh_client->exec($cmd);