1

From my laptop, I'm trying to copy a directory of files from one Raspberry Pi (pi@192.168.2.22) to another (pi@192.168.2.21):

~/example$ scp -r pi@192.168.2.22:~/example/files_to_send pi@192.168.2.21:~/example

but I keep getting this error message after I enter the password for pi@192.168.2.22 (the host from which the directory is to be copied):

pi@192.168.2.22's password:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
lost connection

I've tried deleting the ECDSA fingerprints in ~/.ssh/known_hosts for each of the devices, and generating new ones by reconnecting each host together again with ssh. I have also ensured that the home directories (and all their contents) have the correct permissions, owner and group.

Also, if access the Raspberry Pi that I'm trying to copy from (pi@192.168.2.22) with ssh, and do the following:

~/example$ scp - r files_to_send pi@192.168.2.21:~/example

It works fine.

I'd like to know why using scp to copy from a remote host to another remote host isn't working.

Any ideas?

EDIT

I discovered the -v option for scp ; here its entry in the scp man page:

Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.

So, I added this to the command, and this indicates that the authentication to pi@192.168.2.22 is successful. However, when pi@192.168.2.22 later attempts to authenticate to pi@192.168.2.21, the following messages are printed and the connection fails:

debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
lost connection
  • Can you actually ssh into the other machine? Also, have you tried this syntax: scp -r directorytosend pi@192.168.2.21:~/example/ – Nasir Riley Sep 29 '18 at 3:24
  • Yes, ssh works fine for all machines. The syntax you suggested works (from pi@192.168.2.2). Cheers – R.Neville Sep 29 '18 at 3:30
  • I'll post it as a answer. – Nasir Riley Sep 29 '18 at 3:32
  • 1
    Ok, thanks. I'd still like to know why remote host to remote host isn't working... – R.Neville Sep 29 '18 at 3:34
  • Do you mean remote host to local host? – Nasir Riley Sep 29 '18 at 3:36
0

When you run an scp on a local client between two remote systems, like this:

scp remote1:file remote2:

You are authenticating to remote1 from your local, as expected, but then it is remote1 that authenticates to remote2 directly. The file transfer is NOT sent via your local client as you might expect.

To tell scp on the client to authenticate to both remote hosts and to manage the file transfer itself you need an additional flag:

scp -3 remote1:file remote2:

In your situation I expect that the first Pi doesn't have a certificate-based login that works without manual involvement set up to the second, so the authentication fails. (Bear in mind your keys appear to require a passphrase to unlock, and that isn't available on the first Pi when it tries to communicate with the second.)


OK, so I can repeat your issue when I have no certificate based authentication set up. It seems that to transfer between two remote systems you must have certificate-based authentication (i.e. no password required).

  • Hi @roaima. Thanks for posting. I've tried using the -3 option, but this presents me with a mashup of two password prompts side by side: pi@192.168.2.21's password: pi@192.168.2.22's password:. When I try entering a password, it responds with Permission denied, please try again, then presents me with another prompt: pi@192.168.2.22's password. But, after I enter it, I then get the message: Connection closed by 192.168.2.22 port 22. I'm stumped that this is also not working... – R.Neville Sep 29 '18 at 9:32
  • What, you get password prompts? Were you getting those on your initial scp attempts too? – roaima Sep 29 '18 at 9:46
  • Yeah, and with my initial attempts I got a prompt for the source host (pi@192.168.2.22), but it would crash before I saw the prompt for the destination host (pi@192.168.2.21). – R.Neville Sep 29 '18 at 9:53
  • @R.Neville answer updated. I'll see if I can find anything definitive on this for you. – roaima Oct 1 '18 at 17:05
  • Thank you @roaima! I setup an RSA key for pi@192.168.2.22 (following this tutorial: digitalocean.com/community/tutorials/…), and it works fine now (scp -r pi@192.168.2.22:~/example/files_to_send pi@192.168.2.21:~/example)! I appreciate you putting in the time to discover this :) – R.Neville Oct 2 '18 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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