0

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 [email protected] "ssh [email protected] "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?

2
  • localhost <---> A (10.10.10.10) <---> B (11.11.11.11) and you cannot directly connect from localhost to B?
    – quanta
    Aug 29, 2011 at 4:27
  • # this does not work from localhost # scp file.txt [email protected]:/home/shantanu/
    – shantanuo
    Aug 29, 2011 at 4:56

1 Answer 1

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.

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