I have two (linux) servers: A and B
A PHP script is on A, I want to execute it on B but without coping it on B, this script should never exist on B (only in ram), so no "copy on B, exec from ssh command on A, erase on B".
I have ssh keys to access B from A, but not A from B. Maybe something like:
ssh root@B 'php -r ' | echo /myscript/on_serverA
or
<?php
$script=file_get_contents('executable_php_script');
system('ssh root@IP \'php -r "'.$script.'"\'');
Any ideas?
Note: it's a very specific case, so I dont want alternative or security advice.
ssh
will be passed into STDIN of the program being runThus:
ssh example.com php < test.php
… will ssh to example.com
, run php
there and pipe the contents of test.php
from the local machine into the remote php
.
With regards to comments on the question: Note that if someone with root access on example.com
wanted to steal the script they could replace the php
executable with a wrapper that logs STDIN to a file before forwarding it to the real php
. This is far from a bullet-proof security measure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.