Execute shell script from browser through php


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute shell script from browser through php
# 1  
Old 11-18-2010
Execute shell script from browser through php

Hi all,
I want to execute a shell script in which I call ssh to execute a remote command.

Everything works fine from command line but when I try to call from PHP (with exec or whatever function) it fails.

After some time I came to the root cause: when www-data execute the ssh command it asks for key-exchange/password even if "ssh -l myuser R_HOST ...".

I'm not a pro with ssh, can you help with some tip?

Thanks,
Evan
# 2  
Old 11-18-2010
The -l myuser flag says, which user to use on the remote end, not the local end. Also, since the directory ~/.ssh is not group/world readable, www-data would not be able to read myuser's private key.

You have to generate a keypair for www-data on the local host and paste www-data's public key into myuser's autothorized_keys file on the remote host.
# 3  
Old 11-18-2010
Thank you hergp for quick reply.
It works but ...

Is it possible to use the -i option specifiyng the myuser id_rsa.pub file?
I tried but I get some errors about file permissions and even copying the id_rsa into www-data .ssh's directory it doesn't work.

This way I can prevent www-data to access remote host unless I specify the id_rsa.pub right? Does this make sense?
# 4  
Old 11-18-2010
By design, the ~/.ssh directory must not be readable by anyone else but the owner. So www-data would not be able to read my_user's private key. If the permissions are set differently, ssh refuses to use the key.

You could copy my_user's keypair into www-data's ~/.ssh directory (changing the owner of the file to www-data). But then you could no longer tell www-data apart from my_user on remote computers and www-data would have access wherever my_user has access. So I advise against doing this, unless you exactly know what you are doing. By the way, it is not such a big effort to create a keypair for www-data and put the public key in my_user's authorized_keys file on the remote computer.

Last edited by hergp; 11-18-2010 at 10:43 AM.. Reason: typo
# 5  
Old 11-18-2010
Ok thanks hergp, I followed your advice.

Kind Regards,
Evan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Php script prints values but not seen in browser

greetings, i'm a php and html novice and i figured i'd learn by diving in. i've written a php script that i've placed in the /var/www/html directory. it's supposed to give some relative info about the system when you point a browser at it. if i run the script using "php -q index.php" all the... (3 Replies)
Discussion started by: crimso
3 Replies

2. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

3. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

4. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

5. Shell Programming and Scripting

Control browser from shell script

I have a browser running in a separate virtual terminal and would like to be able to send shortcut codes (e.g. ctrl+A) to the browser (and have it react) from a bash script in a separate virtual terminal. I need to keep the script in the separate virtual terminal. (2 Replies)
Discussion started by: slak0
2 Replies

6. Shell Programming and Scripting

Execute interactive bash menu script in browser with PHP

I have an interactive menu script written in bash and I would like use PHP to open the interactive bash menu in a browser. Is this possible? Using the sytem() function in php runs the script but it's all garbled. Seems like maybe a terminal window needs to be opened in php first? ... (1 Reply)
Discussion started by: nck
1 Replies

7. Shell Programming and Scripting

How can i write a script to execute commands on the webserver from a browser?

I want to create a script with the php exec() or system() function to execute commands from a remote browser on the webserver. I am open to using Perl or whatever. I am using an Apache2 webserver on Ubuntu. I have done quite a bit of research on this on google and read lots of responses about... (0 Replies)
Discussion started by: bash_in_my_head
0 Replies

8. UNIX for Dummies Questions & Answers

run shell script from browser

my shell script is to reset user menu: #!/bin/ksh echo "Type in login id: \c" read username if then echo "....." echo "You have not entered any INPUT value." echo "...Goodbye..." sleep 10 exit else echo $username rm -f... (3 Replies)
Discussion started by: tjmannonline
3 Replies

9. UNIX for Dummies Questions & Answers

Need Shell script for getting Firefox Browser Version

Hi, How to write a script for finding out firefox version in our linux machine? Could you please share the same? I am using Red Hat Linux machine. Thanks, Kammy (2 Replies)
Discussion started by: kjannu
2 Replies

10. Shell Programming and Scripting

Is it possible to execute shell script with PHP?

I'm trying to write a php script that can let user reset to the default password. I already have a shell script that does this job, so I wonder is it possible to execute shell script with PHP? If yes, then how? Thx in advance (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question