Run SSH from PHP with Browser, not with Command Line (CLI)

On Jan 1, 2010 0 comments

This was my question how to run ssh from php on my Ubuntu. Many people know that to run Linux command from php is by using function like exec(), shell_exec(), system(), passtrhu(), etc. Everything seems very easy to do. Maybe you can run almost all Linux command with php. You could run ssh too with php CLI. But you maybe stuck why you can not run ssh from php with your browser.

Command like ls, ping, and all internal command was run well both on php CLI and browser, but not with ssh. This is because the user name who run php is different between the terminal and the browser.

On terminal you got result your login name, and on browser you will get user "nobody" (when you using Lampp like me). This is because that the default, apache using user nobody.


To make ssh work on your code, you need to change the user nobody with your user name. To do it, open the httpd.conf file, and find this :

User nobody
Group noody

Then changes it with your user name and group. And thats will do it. But you need to remember about the security when do this. Hope this help everyone who has problem with ssh and php.

0 comments:

Post a Comment