This question is related to the two other questions I had earlier, about enabling Raspberry Pi to act as a motion sensor that will try to ssh into a more powerful server when it detects motion (the more power server will then do additional processing via a script). So here's what I did:

  • On the Raspberry Pi, I installed Linux motion app
  • I also used ssh-keygen on the Raspberry Pi and then using ssh-copy-id copies public keys to the more power server, so that the Raspberry Pi can ssh to the server without having to type in the password.
  • On the motion.conf file, there's a line for on_motion_detected event for when the motion is detected by Raspberry Pi, on that line, I have something like:

    ssh [email protected] '/exec/some/script/here'

  • But the script on the more powerful server is never executed because the motion daemon is running as user 'motion', rather than the user (pi) that did the ssh-keygen that the remote server accepts. I know this because:

  • If I change the on_motion_detected command to:

    on_motion_detected echo hello_world | wall

    this command gets executed and I see it on all the terminals that are ssh'd into the Raspberry Pi

  • Or, if instead of on the on_motion_detected line, I simply run ssh [email protected] '/exec/some/script/here' on the Raspberry Pi's command line (as user 'pi'), it also gets triggered by the server.

So the question is, how do tell the Raspberry Pi's operating system to 'use' the key of the 'pi' user when the 'motion' user tries to ssh into the more powerful server, in that on_motion_detected event?

2 Answers 2


One option is moving your ssh-keys from pi user to motion user.

(Assuming that your home user of pi and motion is /home/pi and /home/motion)

# mkdir /home/motion/.ssh/
# cp -a /home/pi/.ssh/* /home/motion/.ssh/
# chown -R motion /home/motion/.ssh/


If not specified, ssh command use key in ~/.ssh/id_*, where ~/ is home directory of user who executed this command. So, if you run as motion user, ssh will try to use key in /home/motion/.ssh/ instead key in /home/pi/.ssh


When I ran Motion on my Raspberry Pi, I found the home directory for motion was


I discovered this by enabling picture saves and running the command

on_picture_save echo $HOME >> /tmp/home.txt

in /etc/motion/motion.conf and examining the result.

Putting the .ssh files in /var/lib/motion/.ssh/ enabled the connection.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .