php - Remote Connection from the ssh2_exec to another remote and access to shell of new connection -
i have connected remote server using ssh2-connect , , using ssh2_exec run command "sshpass -p 'xxxx1248' ssh xx@1x2.1xx.3x.xx " , if connected new remote server want access shell. have task run command on there in second remote server. how ??
$connection = ssh2_connect($sip, $iport);  $autherised = ssh2_auth_password($connection, $susername, $spassword); $oresult = ssh2_exec($connection, "sshpass -p 'xxxx1248' ssh xx@1x2.1xx.3x.xx"); how access shell of ip 1x2.1xx.3x.xx.
please solve if 1 has done before ....
i provide code snippet run "ls" command on target machine. let me know if want.
$conn = ssh2_connect($host, $port); ssh2_auth_password($conn, $user, $pass); // runs ls -al command on $targethost $stream = ssh2_exec($conn,     "sshpass -p '{$passtarget}' ssh $targetuser@$targethost ls -al" );  // retrieving data stream_set_blocking($stream, true); $output = ssh2_fetch_stream($stream, ssh2_stream_stdio);  echo stream_get_contents($output); this code outputs directory listing on $targethost machine.
i hope helps.
edit:
i add example here:
on target machine, created small bash script, test.sh:
export test_var=1 then changed ssh2_exec line to:
$stream = ssh2_exec($conn,     "sshpass -p '{$passtarget}' ssh $targetuser@$targethost 'source test.sh; echo \$test_var'" ); i expected result: 1
Comments
Post a Comment