with scp I can get a file

 scp remoteA:file .

and put a file

 scp file remoteB:

but when I try

 scp remoteA:file remoteB:

I get

ssh: Could not resolve hostname remoteB: Name or service not known
lost connection



the remoteA and remoteB description is in ~/.ssh/config

  • Using scp to copy between two remote hosts works perfectly fine for me. Are you sure you haven't made a typo in your command (like you have made in your question title)? – aland Apr 30 '12 at 16:31

likely not related to scp itself, but some sort of name resolution from one host to another. another thing to consider is authentication. it is best you have a passphrase-less key auth from A to B. in which host's .ssh/config you are defining these hosts? scp is not finding that definition. try the real fqdn of the host and it should work fine, if host definition is the problem. also, use -v to see if more details can be found for the error.

  • If you're able to ssh into remoteA, can you connect from remoteA to remoteB? – Doug Harris Apr 30 '12 at 17:26

You need to specify a host which remoteA can reach because the copy is made from remoteA directly to remoteB.

To avoid this you can use the -3 option. man scp says what it does:

Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter.

  • It can be argued whether this should be a default or not, I certainly did expect it to be, otherwise I'd just ssh into remoteA and do a normal scp while enjoying that sweet path auto-completion. Anyway this answer saved my sanity, so thanks. – JohnTheWalker Sep 6 '19 at 9:22

For those who come here because scp accuses a local file of being a hostname which it can't resolve (another source of Name or service not known), such as:

> scp archive_2017-03-01-09:54:02.tar.gz backupserver:/var/backups/
ssh: Could not resolve hostname archive_2017-03-01-09:54:02.tar.gz: Name or service not known


> scp ./archive_2017-03-01-09:54:02.tar.gz backupserver:/var/backups/

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.