-1

Servers aren't visible, they are hidden behind another server. In order to make them visible you have to log into the first server over ssh. Once there the other servers are visible and you can ssh into them from the current server (the one you just logged into/ssh'ed into).

I want to be able to run commands on the very last server in my script.

Is it possible to SSH into one server, than ssh into the next server from the current server we ssh'ed into using phpseclib and run commands?

It looks possible in the libssh2 examples for ssh2 functions on the PHP man pages so I was hoping it was possible with this library as well. Anyone had similar requirements?

Thanks.

fr332lanc3
  • 151
  • 1
  • 11
  • libssh2 has an ssh2_tunnel function I assumed you could go off the existing connection, specify the subsequent host, and you'd be tunnelled through from your origin, to the middle box, followed up by the end box (which you connected to from the middle box). It's tricky with password authentication but doable (more complex) and easier with keys for authentication. – fr332lanc3 Jul 15 '14 at 15:34
  • I don't think the `ssh2_tunnel` function works the way you think it does. `ssh2_tunnel` lets you send unencrypted data to a server via `fputs()` or `fwrite()`. eg. you could do `fputs($tunnel, "GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n"); fread($tunnel, 1024);` but you'd have to essentially re-implement SSH in PHP to make libssh2 tunnel SSH to SSH. That's essentially what PHP does so you could modify it to use ssh_tunnel. I'll try to update my earlier answer with a demo of how this could be done as time permits. – neubert Jul 15 '14 at 17:00
  • Makes sense. It's easy enough to do manually but not ideal scripting. – fr332lanc3 Jul 16 '14 at 19:16
  • Try this: http://pastebin.com/aTJ48HPH – neubert Jul 16 '14 at 21:43
  • That uses ssh2 which was what I was talking about before with the tunnel function, however we don't have access to libssh2 on windows boxes. I tried searching for binaries and setting it up but failed, using a windows workstation with linux servers unfortunately. – fr332lanc3 Jul 17 '14 at 16:32
  • Ah right. Well phpseclib doesn't currently support tunneling itself. idk how hard it'd be to implement. Maybe try posting a feature request on phpseclib's github.com account? – neubert Jul 17 '14 at 17:07

1 Answers1

-1

You could do $ssh->exec("ssh user@domain.tld 'ls -l'");. I don't think you could do much more than that even with libssh2. If you can could you update your orig post to include an example?

neubert
  • 15,947
  • 24
  • 120
  • 212
  • I can give that a try, but it may not meet the needs of some of the interaction required on the terminal, this would also require every command be ran after an ssh/login which isn't ideal. I updated my post with a comment about ssh2_tunnel for libssh2, it's doable via that library and I think PHP man pages have examples. – fr332lanc3 Jul 15 '14 at 15:35
  • So use ; to add multiple commands? And what about auth only user/pass or can I use keys as well? – fr332lanc3 Jul 16 '14 at 19:16
  • For auth for SSH you can use sshpass or any of the methods suggested here: http://stackoverflow.com/a/16734873/569976 . A public key in the appropriate .ssh\id_rsa file (with the appropriate permissions) should do the trick as well. – neubert Jul 16 '14 at 22:08