0

I have local machine (L) and a remote machine (R) which is only reachable by hopping over (A), (B).

For transvering a file my normal routine looks likes this:

l@L$ ssh -t a@A ssh -t b@B ssh r@R
r@R$ # do some stuff till I find out I want to copy file x to L

I then open a new terminal

l@L ssh a@A
a@A ssh b@B
b@B scp r@R:PATH_TO_FILE a@A:TEMP
b@B <ctrl-D> to close
a@A scp TEMP r@R l@L:FINAL_DESTINATION

and scp my file over all the hops.

I wonder if there is a shell extension or program which would allow to copy files directly from R. Something akin of piping stdout@R to stdin@L to cat it. It doesn't have to be terribly efficient. As most of the time my files are small (<100kB), but it needs to support binary.

magu_
  • 101
  • @Jakuje: I disagree, I specifically ask for a way to copy it directly: e.g. without a prior setup like port forwarding. My reasoning is that the terminal should have access to both L and R. – magu_ Jan 06 '17 at 16:52
  • The none of the questions does set up any port forwarding. It does standard stdio forwarding, which is preferred way of proxying (unlike the ssh 1 ssh 2 ssh 3 chain). – Jakuje Jan 06 '17 at 16:54

1 Answers1

0

You might want to look into ssh's ProxyCommand configuration, which allows for this to work more seamlessly, and will work for shells, SFTP, tunnels, and anything else you might want to proxy via ssh.

Let's say you have the following three hosts:

  • workstation.example.com - This is the machine you're physically working on
  • proxy.example.com - This is the machine you're routing your SSH traffic through
  • endpoint.example.com - This is where you want the traffic to ultimately end up

In ~/.ssh/config on workstation, add the following:

Host endpoint
    User WorkstationUser # set this to the username on the workstation host
    HostName endpoint.example.com
    ProxyCommand ssh username@proxy.example.com nc %h %p 2> /dev/null

On the proxy host, make sure nc (netcat) is installed.

Then, on workstation, you can ssh endpoint or sftp endpoint and you will be transparently proxied to the machine by way of your proxy host.

DopeGhoti
  • 76,081