Problem: There are 3 devices: My server (Linux), the jump server (Linux) and a Cisco box. I can manually ssh onto the jump server and from there ssh to the Cisco box and run commands interactively. Is there a way I can acheive this programatically using PHP? I want to be able to interogate the responses from the Cisco box as I go and tailor the next commands accordingly. I have done similar things in Python but was able to connect directly using socket (no jump server in between) but I prefer using PHP if I can.
Asked
Active
Viewed 273 times
1 Answers
0
man ssh
:
-t Force pseudo-terminal allocation. This can be used to execute
arbitrary screen-based programs on a remote machine, which can be
very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Therefore, ssh -t jump_server ssh -t cisco_box ...
Also, you can use such command in PHP via proc_open or exec. Then you will have stdin, stdout, and stderr (along with other file descriptors) of the executed ssh available in PHP, so you can send/receive commands and data to/from the cisco box.
It depends on the program on the other end whether it needs tty or not (which -t
enforces). Programs like mc do need tty, but most command line tools don't (then simply ommit the -t
).

Josef Kufner
- 2,851
- 22
- 28
-
If this idea has any validity, how could I wrap it in PHP and then send commands and receive output. I'm sorry but I find it a little to vague for me to understand at this time. – John_F Mar 02 '17 at 07:00
-
After many unsuccessful attempts, I am now trying with Python. My new question is at http://stackoverflow.com/questions/42557671/how-do-i-capture-password-prompt – John_F Mar 02 '17 at 14:13
-
Try simpe use from shell, when it works, figure out how to call it from PHP. – Josef Kufner Mar 02 '17 at 18:30