Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's an interesting situation. I have:

  • A Linux box that is a motion sensor and can execute command line commands upon receiving a motion event (see the Linux motion app).
  • Another Linux box that (I would like to) dedicated to additional processing in the event that a motion is detected.

The reason I don't want the first Linux box to do additional processing is that it is woefully underpowered and isn't conveniently connected to other systems that I'd like to activate.

So my question is, how do I broadcast or send machine readable code from that first Linux box to another Linux box (or any ssh client) to trigger further processing based on the type of code? I tried the broadcast command but for some reason, it shows up as empty in the clients instead of a specific code. In addition, how do I enable the 2nd Linux box to act upon the code? Should it be a cronjob or some sort of listener?

share|improve this question
If you're new to making SSH keys: cyberciti.biz/faq/…, or here: digitalocean.com/community/articles/how-to-set-up-ssh-keys--2 – slm Feb 2 '14 at 0:21
Thanks! This is quite helpful. – Uzumaki Naruto Feb 2 '14 at 0:32
Any particular reason you're set on sending data over ssh? Personally I'd use syslog for this. The system is (likely) already going to have a syslog daemon running, just configure it to forward its logs to a remote host. Have the utility write it's logs to syslog, and then have something on the remote host use the logs. If you're using syslog-ng, you can have it filter the logs and only send specific ones to your application. – Patrick Feb 2 '14 at 20:47
I wanted to make the communication secure. But to be honest, I'm kind of fuzzy on linux security so if you think there is a better solution, please let me know, would be happy to try! – Uzumaki Naruto Feb 5 '14 at 14:14
up vote 1 down vote accepted

Step #1

First make sure the motion sensor box has a SSH private key set up on it: ssh-keygen.

Step #2

Then make sure the public key for said private key is on the more powerful computer. You need to put it at the end of a file with a name like this:


NOTE: ${user} is your user's name on the more powerful computer.

Also, make sure on the powerful computer, /home/${user}/.ssh/ has the permissions 700 (drwx------), and /home/${user}/.ssh/authorized_keys has permissions 600 (-rw-------). You can use the chmod to set permissions.

$ chmod 700 /home/${user}/.ssh/
$ chmod 600 /home/${user}/.ssh/authorized_keys

Step #3

Then, from the remote sensor computer, run something like:

$ ssh user@more-powerful-computer '/usr/local/bin/process_motion_event'
share|improve this answer
I really like this answer, but for some reason step 3 doesn't quite work. so in the motion linux app, on the on_motion_detected line, I have the command: sudo ssh user@more-powerful-computer "mplayer ~/test.mp3", but it doesn't work due to pubkey being denied. If i just directly run that sudo command from the sensor box, it also doesn't work...it will only work with regular ssh, not sudo ssh. However, the motion app won't trigger any event without the command being sudo. – Uzumaki Naruto Feb 2 '14 at 1:46
You will have to permit root logins on more-powerful-computer then do ssh root@more-powerful-computer mplayer /root/test.mp3. This is because that sudo command makes you root on the monitor, not more powerful computer. To enable root logins (if not already done), may may need to edit the file /etc/sshd_config (or is it /etc/ssh/sshd_config?). – samiam Feb 2 '14 at 2:10
It should also be noted that, because root on the local machine is executing the ssh, ssh will look for the private key in root's home directory, not yours. (Also: does mplayer really require root? It seems to me something like simply playing an audio file shouldn't require root (OS X's afplay doesn't), and to me it doesn't seem a very good idea security-wise to enable root logins just for that.) – Blacklight Shining Feb 2 '14 at 4:56
To your point Blacklight - how do I make motion run as regular user, so that it won't need sudo to ssh. – Uzumaki Naruto Feb 2 '14 at 15:19
@UzumakiNaruto I have no idea. What happens when you try? (Actually, you should probably ask a new question for that.) – Blacklight Shining Feb 2 '14 at 20:34

This worked on my network

  rsh myuser@ mplayer /home/myuser/FF_Fanfare.mp3

It required me to type my password. To get around that you can use ssh profiles or public keys, as the samiam noted.

share|improve this answer

You have a number of ways to connect two machines. Via ssh is one of them. The easiest way however is to use NetCat (man nc) which is by default available for many Unices.

On another box (box1):

nc -l -p 9999|while read line; do echo $line; done

On sensor box (box0):

echo "sensor code"| nc box1 9999

So box1 receives all input box0 sends.

If you want to use ssh:

On sensor box (box0):

echo "sensor code" | ssh box1 'cat >> /path/sensor.log'

On another box (box1):

tail -f /path/sensor.log|while read line; do echo $line; done
share|improve this answer
What are the advantages of this relative to the ssh method? – Uzumaki Naruto Feb 2 '14 at 0:39
There are dis- and advantages, nc does not use encryption so on your weak box is not much data crunching needed and you send data faster than on ssh. Disadvantages: if you need to send your data encrypted you'll need to use ssh or nc via ssh, but there are too many ways of doing that. – user55518 Feb 2 '14 at 0:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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