Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I dislike calling scp twice.

I need to connect to box1 via ssh the again to boxNAME. How do i copy a file from boxNAME to my local drive? also how do i copy a file from my local drive back to boxNAME?

alternatively if i can grab a file (either one) and output it and use it as a stdin on the other side that would work just as well. (The files are <4k and text). Bonus point if you can tell me how to create a text document and use stdout to write and save (remember this is across 2 connections not local in which case i'd do cat file >>out.txt)

share|improve this question

Have you tried something like this ?

ssh user@host1 "ssh user@host2 'cat file.txt' " > local_file.txt
share|improve this answer

I think the easiest method might be to simply use port forwarding. Start a session to the intermediate box and forward some port to allow ssh connection to the far host. Then simply use scp via your port forward.

If you need to do this regularly, you could create a ssh configuration that uses the ProxyCommand directive.

Host farhost
    ProxyCommand /usr/bin/ssh username@intermediate "/bin/netcat -w 1 farhost 22"
    User username

Given something like the above you can make connections to the far host as if it was directly connected. For this to work the best you'll want to setup key-based authentication.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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