2

I want to copy a file from a remote host (remote1) to another remote host (remote2) via my local machine. I can only establish ssh connections from this local machine to either of the two remotes. They have no connection between each other nor can I connect to local from any of the remotes.

I read I should use scp -3 user@remote1:Folder/file user@remote2:Folder/ but unfortunately the scp version is too old for -3. So I read I need a ssh tunnel. Can you walk me through it?

2
  • 2
    try sshfs to mount the second endpoint to a location on your system, and copy the files from the first system into it: en.wikipedia.org/wiki/SSHFS Dec 17, 2014 at 15:22
  • sshfs is not available on the system. I also have no root acces to any of the machines if that matters for the answer...
    – Moritz H.
    Dec 17, 2014 at 15:35

1 Answer 1

1

You will need two shell sessions. On the first shell you type:

ssh user_r1@remote1 -L 2222:localhost:22

Then, on the second shell:

ssh user_r2@remote2 -R 2222:localhost:2222
ssh user_r1@localhost -p 2222

In the first shell you will connect on remote1, and redirect traffic from port 2222 on your local machine to port 22 on remote1.

In the second shell you will connect on remote2, and redirect traffic from port 2222 from remote2 to port 2222 on local machine.

Then, connected on remote2, if you try to ssh (or scp) on localhost, port 2222, the traffic will be redirected to remote1 on port 22.

1
  • Thank you very much for this. It works very well. Although I'd like to note that the p switch from ssh corresponds to the P switch (uppercase) from scp :)
    – Moritz H.
    Jan 2, 2015 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .