php ssh连接phpseclib [英] php ssh connection phpseclib

查看:250
本文介绍了php ssh连接phpseclib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

System: Linux
Server: XAMPP
Goal:
ssh-connection to a server (later: doing some stuff on this server, not part of this question)

测试代码:

 <?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中),因此:
问题:
为什么我没有得到任何输出(用户,主机名)? 还有其他/更好的方法来检查我的连接是否正确吗?

Output:

connected
(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:
Question(s):
Why am I not getting any output (user, hostname)? Are there other/better ways to check whether I am properly connected?

推荐答案

看起来您正在获得输出. (M4300-28G-PoE+) >是您正在获取的输出,并且正在为您尝试运行的两个命令获取它.

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. Switches are fairly notorious for not having full SSH implementations.

我的猜测:如果要运行命令,则必须使用phpseclib的交互式命令:

My guess: if you want to run commands you'll have to use phpseclib's interactive commands:

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

这篇关于php ssh连接phpseclib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆