简体   繁体   English

无法使用 phpseclib 连接到远程服务器

[英]unable to connect to remote server using phpseclib

I have an odd issue on our inhouse backup app when I try to access one of the severs.当我尝试访问其中一台服务器时,我们的内部备份应用程序出现了一个奇怪的问题。 I have taken out the code that our connectivity test uses and placed it in a test file so as to see what is breaking.我取出了我们的连接测试使用的代码并将其放在一个测试文件中,以便查看有什么问题。 The issue is the same weather I run this from the apps server or my own devbox.问题与我从应用程序服务器或我自己的开发箱运行它的天气相同。

I have enabled password logging on the remote box too but it doesn't matter if I use my version or our production version as we are unable to login using either the password or the pem we use to connect to other servers using the same provider (Digital Ocean)我也在远程机器上启用了密码登录,但是我使用我的版本还是我们的生产版本都没有关系,因为我们无法使用我们用来连接到使用同一提供商的其他服务器的密码或 pem 登录(数字海洋)

So here is the code in a test-ssh.php file (I've changed the url, user and password for obvious reasons) the port is 22 so not used in code.所以这里是 test-ssh.php 文件中的代码(出于明显的原因,我已经更改了 url、用户和密码)端口为 22,因此未在代码中使用。

<?php

<?php
// Autoloader
include('./autoloader.php');
use phpseclib\Net\SSH2;

const NET_SSH2_LOGGING = 'NET_SSH2_LOG_COMPLEX';

ini_set('display_errors', true);
ini_set('error_log', 'php-error.log');

$ssh = new SSH2('123.123.123.123');
if (!$ssh->login('the-user', 'my-password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->getLog();

The code runs until it reaches the $ssh->login line where it just exits with no error.代码运行直到它到达 $ssh->login 行,在那里它没有错误地退出。 I have tried to step through this but it is very unclear what is going on.我试图逐步解决这个问题,但目前还不清楚发生了什么。

My logs have nothing new added when this is run and nothing is shown on the screen.运行时我的日志没有添加任何新内容,屏幕上也没有显示任何内容。

Both servers are running php8.1 and ubuntu 22.04 and as mentioned already we have other projects on other DO droplets (also on ubuntu 22.04 and php8.1 in some cases) but these work as intended and it is only this 'new' one that is breaking两台服务器都在运行 php8.1 和 ubuntu 22.04 并且如前所述,我们在其他 DO droplet 上还有其他项目(在某些情况下也在 ubuntu 22.04 和 php8.1 上)但是这些按预期工作并且只有这个“新”的坏了

Changing credentials to another box we know works does work on both my box and our backup server.将凭据更改为另一个我们知道有效的盒子在我的盒子和我们的备份服务器上都有效。 At a complete loss and have been trying to resolve this for over a week!完全不知所措,一个多星期以来一直在努力解决这个问题!

thanks谢谢

*** EDIT *** after adding eror reporting back i now got the following errors *** 编辑 *** 添加错误报告后我现在得到以下错误

Warning: unpack(): Type C: not enough input, need 1, have 0 in /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php on line 1446

Fatal error: Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, bool given in /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php:1446 Stack trace: #0 /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php(1446): extract() #1 /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php(1128): phpseclib\Net\SSH2->_key_exchange() #2 /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php(1904): phpseclib\Net\SSH2->_connect() #3 [internal function]: phpseclib\Net\SSH2->_login() #4 /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php(1888): call_user_func_array() #5 /hdd/projects/local.backup.ecl/htdocs/test-ssh.php(12): phpseclib\Net\SSH2->login() #6 {main} thrown in /hdd/projects/local.backup.ecl/htdocs/phpseclib/Net/SSH2.php on line 1446

Thanks to pointers and advice above from Chris Haas and neubert, I upgraded my phpseclib (it was 2 so upgraded to 3 as think the new server is using ecdsa which is what I now think to be the most likely cause for this error) and generally upgraded all I could with some refactoring and this is now giving the expected path to working directory and otherwise in a good point (still some amends left out of scope here)感谢上面 Chris Haas 和 neubert 的指点和建议,我升级了我的 phpseclib(它是 2 所以升级到 3 因为认为新服务器正在使用 ecdsa 这是我现在认为最有可能导致此错误的原因)并且通常通过一些重构升级了我所能做的一切,这现在给出了工作目录的预期路径,否则就很好(这里仍然有一些修正遗漏了 scope)

thanks谢谢

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

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