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

~/example$ scp -r pi@ pi@

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

pi@'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@ with ssh, and do the following:

~/example$ scp - r files_to_send pi@

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?


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@ is successful. However, when pi@ later attempts to authenticate to pi@, 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@ Sep 29, 2018 at 3:24
  • Yes, ssh works fine for all machines. The syntax you suggested works (from pi@ Cheers
    – R.Neville
    Sep 29, 2018 at 3:30
  • I'll post it as a answer. Sep 29, 2018 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, 2018 at 3:34
  • Do you mean remote host to local host? Sep 29, 2018 at 3:36

1 Answer 1


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