php ssh连接phpseclib

问题描述 投票:0回答:1

系统:Linux 服务器:XAMPP 目标: ssh连接到服务器(后来:在这个服务器上做一些东西,不是这个问题的一部分)

测试代码:

 <?php  
    set_include_path(get_include_path().PATH_SEPARATOR.'/home/myusername');
    include('Net/SSH2.php'); 
    $ssh = new Net_SSH2('123.45.6.78'); 
    if (!$ssh->login('user', 'password')) { 
    exit('Login Failed'); 
    }else{ 
    echo "connected".'<br>'; 
    echo $ssh->exec('whoami').'<br>';
    echo $ssh->exec('hostname')).'<br>';
    }   
    ?>

输出: 连接的 (M4300-28G-PoE +)> (M4300-28G-PoE +)> 问题: 我没有收到任何错误(无论是在网站的输出中(见上文)还是在/ opt / lampp / logs / error_logs中),所以: 问题(S): 为什么我没有得到任何输出(用户,主机名)?是否有其他/更好的方法来检查我是否正确连接?

php linux ssh xampp phpseclib
1个回答
0
投票

看起来你正在获得输出。 (M4300-28G-PoE+) >是你得到的输出,你得到的是你试图运行的两个命令。

M4300-28G-PoE +是NetGear switch。交换机因没有完整的SSH实现而臭名昭着。

我的猜测:如果你想运行命令,你将不得不使用phpseclib的interactive commands

echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n"); // note the "\n"
echo $ssh->read('username@username:~$');
© www.soinside.com 2019 - 2024. All rights reserved.