简体   繁体   English

php ssh连接phpseclib

[英]php ssh connection phpseclib

System: Linux 系统:Linux
Server: XAMPP 伺服器:XAMPP
Goal: 目标:
ssh-connection to a server (later: doing some stuff on this server, not part of this question) ssh连接到服务器(后来:在此服务器上做一些事情,不属于此问题)

Test-Code: 测试代码:

 <?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>';
    }   
    ?>

Output: 输出:

connected 连接的
(M4300-28G-PoE+) > (M4300-28G-PoE +)>
(M4300-28G-PoE+) > (M4300-28G-PoE +)>

Problem: 问题:
I do not get any errors (neither in the output of the website (see above) nor in /opt/lampp/logs/error_logs), so: 我没有收到任何错误(无论是在网站输出中(见上文)还是在/ opt / lampp / logs / error_logs中),因此:
Question(s): 问题:
Why am I not getting any output (user, hostname)? 为什么我没有得到任何输出(用户,主机名)? Are there other/better ways to check whether I am properly connected? 还有其他/更好的方法来检查我是否连接正确吗?

It looks like you are getting output. 看来您正在获得输出。 (M4300-28G-PoE+) > is the output you're getting and you're getting it for both of the commands you're trying to run. (M4300-28G-PoE+) >是您正在获取的输出,并且您正在为要尝试运行的两个命令获取它。

M4300-28G-PoE+ is a NetGear switch . M4300-28G-PoE +是NetGear交换机 Switches are fairly notorious for not having full SSH implementations. 交换机因没有完整的SSH实现而臭名昭著。

My guess: if you want to run commands you'll have to use phpseclib's interactive commands : 我的猜测:如果要运行命令,则必须使用phpseclib的交互式命令

echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n"); // note the "\n"
echo $ssh->read('username@username:~$');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM