Ale*_*dre 5 php linux windows ssh ssh-keys
目前,我面临着一个难题,我在网上找不到任何可以帮助我的东西。
我想通过SSH从服务器连接到另一台服务器以发送指令(第二台服务器管理Wi-Fi授权)。
尽我所能说,我认为问题是因为我们更新了一台服务器。(我不确定这个问题是否已经出现了)。
我来自Windows Server,我想给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;
}
Run Code Online (Sandbox Code Playgroud)
这是警告:
警告:ssh2_connect()[function.ssh2-connect]:启动SSH连接时出错(-5):无法在第203行的../aff_wifi.php中交换加密密钥
203行就是这个:
$connection = ssh2_connect($infoConnection["hostname"], 22);
Run Code Online (Sandbox Code Playgroud)
当我“捕获”警告时,我有以下提示:
错误类型:2消息:ssh2_connect()[function.ssh2-connect]:无法连接到ipAdress文件:.. \ aff_wifi.php行: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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3941 次 |
最近记录: |