Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch interactive SSH bash session from PHP

Tags:

bash

shell

php

I'm using PHP to write shortcuts for common server admin tasks (I'm using deployer.org but this shouldn't be important). I want to add a task for starting an interactive bash prompt after SSHing into a server. For example, you would run "./dep ssh" (where "dep" is a PHP script) and this would have the same effect as running e.g. "ssh user@server" from the terminal. Is there a way to do this in PHP? For context, I have about 5 servers that I frequently want to SSH into, or read logs, or copy files etc. so I want shortcuts for this.

The closest I've been able to get is something like this:

$ph = popen("bash","w");
  while(($line = fgets(STDIN)) !== false){
      fputs($ph,$line);
 }
 pclose($ph);

This lets you send commands to and from bash but you don't see the normal bash prompt or get tab completion. I need something like this but with all the normal bash features working.

like image 589
fstr Avatar asked Dec 22 '15 03:12

fstr


1 Answers

If you are simply looking to do SSH in web-browser this is what you are may be looking for one of the following products:

  • Google's Secure Shell extension for Chrome and Chromium
  • Anyterm
  • Ajaxterm
  • Gate One
  • webmux
  • WebShell
  • EC2Box
  • KeyBox
  • KeyBox-OpenShift
  • Mist.io

Here is a link that you might like taking a look at.

like image 151
anand Avatar answered Nov 13 '22 13:11

anand