Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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@10.10.10.10 "ssh shantanu@11.11.11.11 "cat /home/shantanu/backup_all_data.sql.zip "" > /home/shantanu/backup_all_data.sql.zip

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 has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
localhost <---> A (10.10.10.10) <---> B (11.11.11.11) 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@11.11.11.11:/home/shantanu/ –  shantanuo Aug 29 '11 at 4:56

1 Answer 1

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.