Running scp through ssh tunnel

Ki Kim's picture

Run scp to machine R, which is only accessible through gateway machine G.

Step 1: Establish SSH tunnel. Pick a temporary port between 1024 and 32768 (1234 in this example). Port 22 will be used by scp.

$ ssh -L 1234:<address of R known to G>:22 <user at G>@<address of G>

# Adding "cat -" will keep it running while above will get you connected to G
$ ssh -L 1234:<address of R known to G>:22 <user at G>@<address of G> cat -

Either way you run it, open another terminal for next step.

Step 2: Run scp against port 1234 pretending 127.0.0.1 (localhost) is the remote machine R, and the command will be sent to R.

$ scp -P 1234 <user at R>@127.0.0.1:/path/to/file file-name-to-be-copied

References:
http://whoochee.blogspot.com/2012/07/scp-via-ssh-tunnel.html
http://www.rzg.mpg.de/networkservices/ssh-tunnelling-port-forwarding

Category: 

Comments

Thanks Kim

it has saved some time for me...

I used just $ scp -P 1234 <user at R>@127.0.0.1:/path/to/file file-name-to-be-copied after created the tunnel connection

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To prevent automated spam submissions leave this field empty.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.