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 need a way of copying a file through nested servers, as in

localhost$ ssh user@host1
host1$ ssh host2

where host2 is on an off-site intranet and not directly accessible.

Is there a way of using scp to copy a file to localhost from host2 through host1 in a single command? Or am I stuck first copying the file to host1 first?

Thanks in advance.

share|improve this question
possible duplicate of How do I do Multihop SCP transfers? – Zoredache Jan 3 '11 at 7:02
Yes, didn't see that. – jvatic Jan 3 '11 at 20:08

What you're really looking for is a way to tunnel SSH connections. I.e.,

ssh -f host1 -L 16384:host2:22 -N

This will setup a tunnel on host1 that tunnels host1:16384 to host2:22. So when you run ssh host1:16384, you'll actually connect to host2. See the link for more in depth information and a nifty howto.

share|improve this answer
Thanks, this works great combined with launchd – jvatic Jan 3 '11 at 20:05

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.