SSHポートフォワードをPHPで実現する方法について教えて下さい。
サーバーA と B はトンネルが出来ており、CからAにSSHで接続してそこからBに接続というのを
実現させたいのです。
PHPを使わず全部コマンドラインでやると出来るのですが、PHPでやるとどうもうまく行きません。
C→A→B
接続元Cから実行するコードです。
lang
1 Aへ接続 2 $connections = ssh2_connect("",22); 3 if ($connections !== false){ 4 $auth = ssh2_auth_password($connections, "", ""); 5 6 if ($auth !== false){ 7 ssh2_exec($connections, "/home/hoge/toLocal.sh"); 8 9 //実行結果の表示 10 //$stream = ssh2_exec($connections, "hostname"); 11 //stream_set_blocking($stream, true); 12 //echo stream_get_contents($stream); 13 14 } 15 } 16 17 ?>
toLocal.sh というのはexpectを使って対話式シェルをスクリプトで実現するもので
PHPを使わずに直叩きでは成功しています。
toLocal.sh
lang
1#!/bin/sh 2 3expect -c " 4set timeout 20 5spawn ssh localhost -p 10022 -l hogehoge 6expect \"root@localhost's password:\" 7send password\n 8 9interact 10"
実行結果の表示はもちろんですがA側のhostnameが表示され
B側の/var/log/secureには Connection closed by 192.168.1.3 と出ています。
うまくやる方法を何かあれば教えてくださると助かります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。