Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 am often in the following situation:

I have two machines, A and B, which are on LANs, and have non-public IP addresses. Machine C is on the same LAN as B, but publicly visible. I would like to copy a file from B to A, so I have to:

  • ssh to C
  • ssh from C to B
  • scp file from B to C
  • scp file from C to A

Given that ssl can do wonderful things with tunnelling displays all the way back from B to A via C transparently, it seems like it should be possible to do the same with files.

Is there a way to use standard ssh/scp to copy from B to A, without having to make a temporary copy on C?

share|improve this question

migrated from Oct 20 '09 at 11:56

This question came from our site for professional and enthusiast programmers.

Welcome to Stack Overflow! This site for programming questions, and your question is more suited for I have voted to move it there; after five people vote it will move automatically. – Greg Hewgill Oct 20 '09 at 8:04

You want to set up port forwarding. When you SSH from machine A to machine B add a tunnel, i.e. add -L 1234:A:22 when tunnelling to B. Then SSH to machine C and scp the files to B on port 1234 (i.e. add -P 1234 to scp). This will actually route to port 22 on machine A which is the ssh port and hence it'll transfer directly.

I don't have three machines with which to try this right now but I think this should work.

share|improve this answer

If you can ssh from C to B and scp to A from C, then I think you should be able to use scp directly from C.

(Using aa.aa.aa.aa as A's IP address and as B's IP address)

  • ssh into C
  • At the command line on C:

    scp aa.aa.aa.aa:/path/to/destination

share|improve this answer
You beat me by 5 seconds. – NVRAM Oct 20 '09 at 15:20
This might not work. If the user can ssh from A -> C, but not from C -> A, the original method described would work, but my solution won't. – Doug Harris Oct 20 '09 at 17:35

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.