Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Possible Duplicate:
Copy a file from remote to local

The following is working as expected and I can copy a file to localhost from server B passing through server A.

ssh shantanu@ "ssh shantanu@ "cat /home/shantanu/ "" > /home/shantanu/

But how do I copy a file from localhost to server B?

share|improve this question

marked as duplicate by quanta, Khaled, Iain, Sven, Chopper3 Aug 29 '11 at 10:35

This question was marked as an exact duplicate of an existing question.

localhost <---> A ( <---> B ( and you cannot directly connect from localhost to B? – quanta Aug 29 '11 at 4:27
# this does not work from localhost # scp file.txt shantanu@ – shantanuo Aug 29 '11 at 4:56

I find the simplest way to do this is to set up an ssh proxy command, which lets me ssh directly to server B from my workstation, bouncing through server A.

In my .ssh/config file on my workstation, I add the following:

Host serverB
    ProxyCommand ssh serverA nc -q 0 IP_of_serverB 22

What this says is that when you connect to a host called "serverB", it will actually set up an ssh connection to serverA first, where it will run "nc" (netcat) which will dump all traffic into port 22 on IP_of_serverB.

When you connect, you first of all make an ssh proxy connection to serverA (so it will ask for your serverA password), and then it makes the real ssh connection to serverB (so it will ask for your serverB password).

Once this works, you can scp directly to serverB, and it will proxy through serverA

This requires that you have the tool "netcat" (/bin/nc) installed on serverA. If you don't have that, there are probably other tools you can use instead, try doing a google search for ProxyCommand

There are other ways you can build up that config, with ssh_config macros and so on, however I find the above format to be the most reliable.

If you have different usernames on serverA and serverB, you can set the usernames in the config file as well. Check the ssh_config manpage, and google for "ssh ProxyCommand" for more information.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.