我现在面临一个难题,我在网上找不到任何可以帮助我的东西。
我想通过 SSH 从我的服务器连接到另一台服务器以发送指令(第二台服务器管理 Wi-Fi 授权)。
据我所知,我认为问题的发生是因为我们更新了一台服务器。 (我不太确定问题是否因此而出现)。
我来自 Windows 服务器,我想调用 Linux 服务器。
这是脚本:
function executeCommand($command) {
$infoConnection = getInfoConnection();
$out = '';
//The Warning occurs here, impossible to go further
$connection = ssh2_connect($infoConnection["hostname"], 22);
if ($connection === false) {
$error = error_get_last();
throw new Exception("
Error Type : ".$error["type"]."<br/>
Message : ".$error["message"]."<br/>
File : ".$error["file"]."<br/>
Line : ".$error["line"]."<br/>");
}
ssh2_auth_password($connection, $infoConnection["username"], $infoConnection["password"]);
$stdio_stream = ssh2_shell($connection);
sleep(2);
fwrite($stdio_stream,$infoConnection["username"]."\n");
sleep(1);
fwrite($stdio_stream,$infoConnection["password"]."\n");
sleep(1);
fwrite($stdio_stream, $command."\n");
sleep(1);
while($buffer = fgets($stdio_stream)) {
$out .= $buffer;
}
fwrite($stdio_stream, 'exit');
unset($connection);
return $out;
}
这是警告:
Warning: ssh2_connect() [function.ssh2-connect]: Error starting up SSH connection(-5): Unable to exchange encryption keys in ../aff_wifi.php on line 203
第 203 行是这一行:
$connection = ssh2_connect($infoConnection["hostname"], 22);
当我“捕捉到”警告时,我有这个:
Error type : 2 Message : ssh2_connect() [function.ssh2-connect]: Unable to connect to ipAdress File: ..\aff_wifi.php Line: 203
你知道为什么会这样吗? 当我尝试使用 PuTTY 从我的服务器连接到另一台服务器时,一切正常
祝你有美好的一天!
最佳答案
我在尝试通过 ssh2_connect 从一个有点旧的 xenial 访问一个焦点 ubuntu 服务器时遇到了这个问题。解决方案是更新 libssh2-1。即使 php 显示旧版本,它也能正常工作。
在 xenial 中,我添加了焦点存储库,然后安装了最新版本的 libssh2-1,重新启动 PHP 以应用并删除了焦点存储库。
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse"
sudo apt-get update
sudo apt -y install libssh2-1
sudo add-apt-repository -r "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse"
sudo apt-get update
关于php - 无法交换加密 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45882200/