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 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置
    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?