How to copy a file using pscp through an intermediary gateway server hop

5

1

I have a linux jump box between me and a remote server. I have seen a few posts on how to do this with scp (e.g. here), but I am on a Windows box, so the situation is slightly different. I want to copy a file from my local windows machine, through a server setup as a gateway between the two. I should be able to do a multi-hop through the intermediate server. So something like this:

A -> B -> C

I don't want to copy the file to B, then log into B and copy the file again. I'd like to be able to run pscp on a number of files to copy them over.

Scott

Posted 2013-04-04T01:45:12.233

Reputation: 1 243

Answers

4

I found that the best way to do this is to first establish a tunnel to the intermediate server (server B in the illustration). Then pscp over this link. I'll step through exactly what I did.

1) Create an SSH connection to serverB in PuTTY

enter image description here

2) For this connection create a tunnel that goes from port 2222 (you can pick another if you want) to serverC at port 22

enter image description here

3) Open a command window in Windows. Navigate to where PuTTY/pscp is installed on your machine (if not on the Path already)

4) Enter the following command (substituting your own values for those in {}):

c:\putty> pscp -P 2222 -pw {myPasswordOnRemoteMachine} c:\dev\fileIWantToCopy.txt {myusername}@127.0.0.1:/tmp

5) On the remote machineC, the file should be in the /tmp directory

Scott

Posted 2013-04-04T01:45:12.233

Reputation: 1 243

An easier alternative on Windows is to just use WinSCP and use the tunnel feature built into that app. – Scott – 2013-05-18T22:41:23.553

1

The easiest solution I found to this problem, was to not use pscp at all. Just use WinSCP to copy the file over.

  1. Enter your final server address (i.e. server 'C' in the question) in the session page and select SCP. enter image description here

  2. Click on 'Advanced...'. Go to Connection>Tunnel. Enter your jump server info here (i.e. Server 'B'). enter image description here

  3. Now just login with either your keyfile or password and you'll be tunneled in.

Scott

Posted 2013-04-04T01:45:12.233

Reputation: 1 243

0

My even more complicated situation: A -> B -> C -> D ->E

I used PuTTY and FileZilla

A my Windows machine, 
B and C are gateways (very limited functionality)
D is the first Linux Machine and 
E is the target Linux Machine

I use PuTTY to: 
    ssh into B (w/username password) (IP of B is predefined in PuTTY) then
    ssh into C (w/username password) then manually
    ssh into D (w/username password) then manually
    ssh into E (at least this uses pubic key login so no uid/password!)

Once this is setup I then add tunnel to the IP of the final machine E in PuTTY thus:
    L7777 172.123.124.125:22



OK now fire up FileZilla:

File > SiteManager:
Setup new connection to:
Host: 127.0.0.1 Port: 7777
Protocol SFTP
Ask for password...

Connect!

xcxc

Posted 2013-04-04T01:45:12.233

Reputation: 121