I need to execute a bash script via a front end Ajax/PHP Site. I have looked into SSH2 and for the life of me can not get it installed.

Now, I know you can use shell_exec but this throws up problems such as authenticating password etc, I can not use SSH keys as the point is it will be deployed in an environment were there are too many servers to event contemplate doing that.

I need a way to create a PHP variable and assign the value of that variable to the output of a bash script on a remote server (IP/Pass) are user input (Security is not a concern, this will be on a locked down local intranet machine only accessible from 1 IP)

I did try sshpass, but that does not seem to return any output.

Does anyone know of a way of doing this?

  • 1
    If you have a lot of servers you should be using configuration management like Ansible to manage their keys. – ceejayoz Jun 14 '17 at 20:12

sshpass should work, but it (in my experience) takes some fiddling with to make it do what you want. That being said, it is a hacky solution in this context. You'd probably be better off trying to get ssh2 installed and running - it provides for precisely what you want to do.

  • Also, sshpass does some tricks with the tty, which is probably why you're having trouble getting the output. Depending on the details of your installation, this may or may not be insurmountable. I would recommend playing with sshpass from the command line – Erick Brown Jun 14 '17 at 21:40
  • SSH2 is a nightmare to install with PHP 7. I did try this stackoverflow.com/questions/14050231/… and have the library, but still says unknown object when try call it >< – TheOne745665 Jun 14 '17 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.