solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Passing file between Pi(s)

Fri Nov 02, 2018 8:09 pm

I want to use

Code: Select all

 scp localfilename username@otherRapsberryIpAddress:remotefilename  
in a cron job. Is there a way to pass along the password?
I'm a total novice, non-programer (...basically a hack.)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Passing file between Pi(s)

Fri Nov 02, 2018 8:32 pm

Use passwordless ssh using keys. Generate a public/private RSA key pair on the local Pi. Copy the public key to the remote pi in /home/username/.ssh/authorized_keys. Now ssh and scp will work between those two without asking for a password. There are instructions somewhere on the Pi website on how to set this up. Ah, here they are https://www.raspberrypi.org/documentati ... ordless.md

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Passing file between Pi(s)

Fri Nov 02, 2018 8:37 pm

You can copy the keys around with ssh-copy-id
In fact all you need is (hit return for all the questions) :-

ssh-keygen
ssh-copy-id username@remotepi

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Passing file between Pi(s)

Sun Nov 04, 2018 7:51 pm

Thanks all! It works!
However I can't use it (scp) in a cron job? I can't even use cron to call a shell scrip (which uses scp.)
Does anyone know a work-around?

THANKS!
Last edited by solo2500 on Sun Nov 04, 2018 9:04 pm, edited 1 time in total.
I'm a total novice, non-programer (...basically a hack.)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Passing file between Pi(s)

Sun Nov 04, 2018 8:33 pm

How are you setting up the cron job? Do you use sudo crontab or just crontab?

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Passing file between Pi(s)

Sun Nov 04, 2018 9:03 pm

rpdom wrote:
Sun Nov 04, 2018 8:33 pm
How are you setting up the cron job? Do you use sudo crontab or just crontab?
sudo

The error I get is "Host key verification failed." HOWEVER... if I run it in a terminal window it works fine and passes the file without error.
I'm a total novice, non-programer (...basically a hack.)

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Passing file between Pi(s)

Sun Nov 04, 2018 9:28 pm

solo2500 wrote:
Sun Nov 04, 2018 9:03 pm
rpdom wrote:
Sun Nov 04, 2018 8:33 pm
How are you setting up the cron job? Do you use sudo crontab or just crontab?
sudo

The error I get is "Host key verification failed." HOWEVER... if I run it in a terminal window it works fine and passes the file without error.
Looks like you added the keys for user 'pi'. If you run scp from the command line without 'sudo' then all is fine.

If you use it from the 'root' crontab then scp will also run as root.
You have to make sure that the keys are created for the correct user (pi and/or root)

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Passing file between Pi(s)

Sun Nov 04, 2018 9:44 pm

Delete the entry from sudo crontab and put the same entry in crontab without the sudo.

Those two commands edit different crontabs. sudo edits the root user's crontab. No sudo edit the pi user's crontab. You want to run as "pi".

solo2500
Posts: 123
Joined: Sat Jul 09, 2016 12:38 am

Re: Passing file between Pi(s)

Sun Nov 04, 2018 9:58 pm

DirkS wrote:
Sun Nov 04, 2018 9:28 pm
solo2500 wrote:
Sun Nov 04, 2018 9:03 pm
rpdom wrote:
Sun Nov 04, 2018 8:33 pm
How are you setting up the cron job? Do you use sudo crontab or just crontab?
sudo

The error I get is "Host key verification failed." HOWEVER... if I run it in a terminal window it works fine and passes the file without error.
Looks like you added the keys for user 'pi'. If you run scp from the command line without 'sudo' then all is fine.

If you use it from the 'root' crontab then scp will also run as root.
You have to make sure that the keys are created for the correct user (pi and/or root)
YES!!! Thats it!
THANK YOU!!!
I'm a total novice, non-programer (...basically a hack.)

Return to “Beginners”