【发布时间】:2018-02-03 13:13:48
【问题描述】:
我现在面临一个难题,我没有在网上找到任何可以帮助我的东西。
我想通过 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;
}
这是警告:
警告:ssh2_connect() [function.ssh2-connect]:启动 SSH 连接时出错 (-5):无法在 ../aff_wifi.php 中的第 203 行交换加密密钥
第 203 行是这一行:
$connection = ssh2_connect($infoConnection["hostname"], 22);
当我“抓住”警告时,我有这个:
错误类型:2 消息:ssh2_connect() [function.ssh2-connect]: 无法连接到 ipAdress 文件:..\aff_wifi.php 线路:203
您知道为什么会发生这种情况吗? 当我尝试使用 PuTTY 从我的服务器连接到另一台服务器时,一切正常
祝你有美好的一天!
【问题讨论】:
-
你在服务器上运行什么版本的 ssh?如果是 v1,请升级。见:bugs.php.net/bug.php?id=57062
-
我用的是0.11版本(SSH-2.0-libssh2_0.11)
-
版本 0.11 可以追溯到 2008 年 12 月 pecl.php.net/package/ssh2,我建议更新。在 linux 服务器上运行
ssh -V并查看它是否安装了 ssh 的最新版本。如果没有,也要更新。 SSH 版本 1 存在严重的安全风险。 -
Windows服务器上PHP的版本还是5.1.6。我可以更新 libssh 吗?库和php版本是否存在兼容性问题?
-
pecl.php.net/package/ssh2/0.13 ssh2 1.0 及更高版本仅适用于 PHP 7。要安装与 PHP 5 兼容的版本,您可以运行“pecl install ssh2-0.13”,这表明您应该能够将 0.13 与任何 PHP5 版本一起使用。但保留当前的 DLL 以防万一它不起作用
标签: php linux windows ssh ssh-keys