0

I was wondering if it was possible to control say RPB (Raspberry Pi B) from RPA, using Linux commands.

The two PIs are on the same network 192.168.1.static-ip-address.

I log into both of them via SSH.

I have an Apache server on one of them, which I can, via PHP, run linux commands on the machine that the server is on, from outside my network.

I wondered if I could send a Linux command via the same Apache server to the other machine; or would it be better to install a separate server on the second machine?

closed as off-topic by Milliways, lenik, goldilocks, RPiAwesomeness, Steve Robillard Dec 2 '14 at 1:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Milliways, lenik, goldilocks, RPiAwesomeness, Steve Robillard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Send a Linux command is a little vague. Do you just want to execute an arbitrary command? If you just want to execute a command on the remote machine you could just use ssh, e.g. ssh paul@raspB 'ls -l' would execute ls -l on raspB as user paul. – joan Nov 22 '14 at 10:23
  • I want to execute arbitrary command on pib from pia, from outside the local network. I hava an Apache server running on pia. I currently ssh in using my windows laptop, from inside the local network, but i want to run the command via a secure website, hosted on pia, but running the command on pib. Lets say the comnand is df-h as an example. I want to display the free space on pib on the website hosted on pia. – reggie Nov 22 '14 at 10:43
  • 1
    Have your PHP run the ssh command. I wouldn't like to consider all the potential security holes though. – joan Nov 22 '14 at 11:14
3

You can execute shell commands remotely using ssh. man ssh has more info than you'll ever want -- here's the essential info:

Let's call the host on which you want the commands to run the target, and the host requesting it the client.

  1. Generate a key using ssh-keygen on the client, using the account that will be making the requests. Accept the default value for any prompts.
  2. Copy the public key (default file name is ~/.ssh/id_rsa.pub) to the target machine, and append to the file ~/.ssh/authorized_keys for the user that will run the commands. You can do this via cat id_rsa.pub >>~/.ssh/authorized_keys
  3. From the client, you should be able to run commands on the target with a command like

    ssh -luser target command

where user is the username to use on the target (can be omitted if same user as the client)

target is the name or ip address of the target

command is the command to execute

An example with a user account jim on target host utilipi might be

ssh -ljim utilipi date

This will run the date command on utilipi and display the output on the client

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