1

I have some files on a server that I'd like to copy on my local machine. The problem is that I can't directly connect to the remote machine, so I need to connect to an intermediate server first, then I can connect to the destination server via the intermediate one. Is there any way to copy the files directly from the destination server to the local machine and somehow bypass the intermediate server?

Thanks

  • How are you connecting to the intermediate? If you are using ssh you can use something called port forwarding to copy the files. It'll look like you are copying directly from the remote but you'll actually be tunneling through the intermediate. The direct path is probably not possible. – B Layer Oct 16 '17 at 10:11
  • @BLayer Thanks a lot for the reply. Yes, I am using ssh to connect to the intermediate server. – Eman Oct 16 '17 at 10:17
  • It worked? I see you accepted. That was fast. :) – B Layer Oct 16 '17 at 10:21
1

Going the direct route is probably not possible. But if you are able to log into the intermediate with ssh and then from there log into the remote with ssh then you can use something called local port forwarding to copy the files on your local machine with scp. It'll look like you are copying directly from the remote but you'll actually be tunneling through the intermediate.

Try the following on two separate terminals (command lines, shells, etc.)

Terminal 1:

# set up 'local port forwarding'
ssh -v -T -N -L 2222:remote:22 username@intermediate

Terminal 2:

# do your scp command(s) like this example
scp -P 2222 localhost:/path/to/file .

Substitute appropriate hostnames or IP addresses for remote and intermediate.

In the scp command /path/to/file is the path on the remote server.

  • I wish I could up vote twice, – Roman Makhlin Dec 17 '18 at 15:12
1

You don't need port forwarding, you can do it with ProxyCommand. Add something like this to ~/.ssh/config:

Host some_name
    Hostname        internal.example.com
    User            internal_user
    ProxyCommand    ssh -A -q -l %r -W %h:%p external.example.com

This will allow you to ssh to the internal machine with ssh some_name, use scp, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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