Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-10-2012, 07:17 AM   #1
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
simple php ssh script does not display on browser

$var=`ssh ls /`;
print "$var";

ssh promts me to enter my password
when i run script.php on bash it outputs but when i run it on my browser it does not output anything
please help how i can show the results on my browser
Old 09-10-2012, 12:47 PM   #2
Registered: Aug 2002
Posts: 13,453

Rep: Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105
What are you trying to accomplish?

With the information provided I would say that when running from a console your script is being interpreted by bash (or other shell) and not php. Since your script is not proper php syntax it fails when run from the browser.

Here is how to run an external command from php.

Here is how to run a command via ssh.

FYI when posting code please use code tags to preserve formatting.
1 members found this post helpful.
Old 09-12-2012, 09:33 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
The Web server, and thus your PHP code, runs as a different UID than your own UID. The UID of the web server requires a password to login, if it's UID allows logins at all. Perhaps specify the username for whom you want the directory listing to be done.
ssh joeBloggs@ ls /
--- rod.
Old 09-12-2012, 10:28 AM   #4
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 258

Rep: Reputation: 54
PHP is a server side programming language. If you need to enter a password for SSH to work in the browser, then it is already too late because the PHP code has been executed. You'd need to put the password in the code somewhere (preferably in an include with read permissions to only apache or whatever web server you use and root) in order to log in.

In other words, once the server passed the page to the browser, PHP has been completely run. The browser just gets html/xml/javascript that PHP generates.


php, ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Creating a basic simple SSH command to a machine over SSL ? Xeratul Programming 1 01-19-2011 11:24 AM
Web browser display issue with PHP? your_shadow03 Linux - Server 3 02-16-2009 07:26 AM
run shell script bash from browser with php achilles Programming 10 08-02-2007 04:44 PM
Simple PHP Script benrose111488 Programming 7 01-31-2005 02:39 PM
a Simple help on PHP Script Gerardoj Programming 1 10-18-2004 09:26 PM

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration