在ssh2中设置ProxyCommand和ProxyAgent

我需要通过php与远程ssh服务器(debug2)建立连接。 在控制台内部,一切正常,但我没有运行我的PHP代码。 我得到以下errormessage:</ p>


ssh2_auth_pubkey_file():[Username]使用公钥验证失败:Callback返回错误</ p>
</ blockquote>

如何在没有注册的情况下建立与debug2的正确连接.example.com?</ p>
nn

我的当前代码如下所示:</ p>

  if(!function_exists(“ssh2_connect”))die(“函数ssh2_connect不存在”.PHP_EOL); 
if(!($ con = ssh2_connect(“this.example.com”,22) )){
echo“fail:无法建立连接”。 PHP_EOL;
} else {
if(!ssh2_auth_pubkey_file($ con,“[Username]”,$ pubkeyfile,$ privkeyfile)){
echo“fail:无法进行身份验证”。 PHP_EOL;
//脚本失败的地方
}其他{
echo“okay:登录...”。 PHP_EOL;
$ tunnel = ssh2_tunnel($ con,'xx.xx.xxx.17',22);
if(!($ stream = ssh2_exec($ tunnel,“ls -al”))){
echo“失败:无法执行命令”。 PHP_EOL;
} else {
stream_set_blocking($ stream,true);
$ data =“”;
while($ buf = fread($ stream,4096)){
$ data。= $ buf;

}
fclose($ stream);
}
}
}
</ code> </ pre>

我当前的ssh_config:</ p>

< pre> 主机示例
HostName this.example.com
用户[用户名]
ForwardAgent是
IdentityFile~ / .ssh / id_rsa

主机debug2
ProxyCommand ssh exmaple -W xx.xx. xxx.17:22
用户[otherusername2]
IdentityFile~ / .ssh / id_rsa
</ code> </ pre>
</ div>

展开原文

原文

I need to establish a connection to an remote ssh server (debug2) via php. Inside the console everything works fine for me, but I doesnt get my php code running. I get following errormessage:

ssh2_auth_pubkey_file(): Authentication failed for [Username] using public key: Callback returned error

How can I establish a proper connection to debug2 without an registration on this.example.com?

My current code look like this:

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist" . PHP_EOL);
if(!($con = ssh2_connect("this.example.com", 22))){
  echo "fail: unable to establish connection" . PHP_EOL;
} else {
  if(!ssh2_auth_pubkey_file($con, "[Username]", $pubkeyfile, $privkeyfile)) {
    echo "fail: unable to authenticate" . PHP_EOL;
    //The point where the script fails
  } else {
    echo "okay: logged in..." . PHP_EOL;
    $tunnel = ssh2_tunnel($con, 'xx.xx.xxx.17', 22);
    if (!($stream = ssh2_exec($tunnel, "ls -al" ))) {
      echo "fail: unable to execute command" . PHP_EOL;
    } else {
      stream_set_blocking($stream, true);
      $data = "";
      while ($buf = fread($stream,4096)) {
        $data .= $buf;
      }
      fclose($stream);
    }
  }
}

My current ssh_config:

Host example
  HostName this.example.com
  User [Username]
  ForwardAgent yes
  IdentityFile ~/.ssh/id_rsa

Host debug2
  ProxyCommand ssh exmaple -W xx.xx.xxx.17:22
  User [otherusername2]
  IdentityFile ~/.ssh/id_rsa

dongweng9474
dongweng9474 经过~3小时的研究,实际上没有办法通过php执行ssh隧道。我现在开始设置一个bash脚本,从我的php内部调用,为我执行必要的步骤。
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问