3

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?

1
  • 1
    Welcome to Stack Overflow! This site for programming questions, and your question is more suited for superuser.com. I have voted to move it there; after five people vote it will move automatically. Commented Oct 20, 2009 at 8:04

2 Answers 2

3

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.

0

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 bb.bb.bb.bb as B's IP address)

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

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

2
  • You beat me by 5 seconds. Commented Oct 20, 2009 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. Commented Oct 20, 2009 at 17:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.