dsj2222222 2017-09-25 14:27
浏览 312

在ssh2中设置ProxyCommand和ProxyAgent

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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器