1

From my laptop, I'm trying to copy a directory of files from one Raspberry Pi ([email protected]) to another ([email protected]):

~/example$ scp -r [email protected]:~/example/files_to_send [email protected]:~/example

but I keep getting this error message after I enter the password for [email protected] (the host from which the directory is to be copied):

[email protected]'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 ([email protected]) with ssh, and do the following:

~/example$ scp - r files_to_send [email protected]:~/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 [email protected] is successful. However, when [email protected] later attempts to authenticate to [email protected], 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
12
  • Can you actually ssh into the other machine? Also, have you tried this syntax: scp -r directorytosend [email protected]:~/example/ Commented Sep 29, 2018 at 3:24
  • Yes, ssh works fine for all machines. The syntax you suggested works (from [email protected]). Cheers
    – R.Neville
    Commented Sep 29, 2018 at 3:30
  • I'll post it as a answer. Commented 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
    Commented Sep 29, 2018 at 3:34
  • Do you mean remote host to local host? Commented Sep 29, 2018 at 3:36

1 Answer 1

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).

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

You must log in to answer this question.

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