How can I use SCP to copy a file from my local machine to a remote server, bypassing the proxy?

When I use scp -r <my_folder> <remote_user>@<remote_machine>:/home/test it gives the following error message:

ssh: connect to host <host_ip> port 22: Connection timed out
lost connection

I am quite new to this subject - any help is appreciated.

  • What do you mean by "bypassing the proxy"? What kind of internet access do you have? Is there even a direct net connection to the outside? – sleske Jul 18 '11 at 10:40
  • Yes... but i think the firewall is blocking me doing this. – Chathuranga Withana Jul 18 '11 at 10:53

If there's a firewall blocking you, then you have to go through the proxy, not attempt to bypass it. You didn't specify what kind of proxy there is (SOCKS/HTTP?).

If the proxy is SOCKS, you just need some program that will "socksify" your scp command, for instance:

  • tsocks, allows you to socksify a specific program by hooking system calls; http://tsocks.sourceforge.net/
  • tun2socks, which I have developed, simulates a virtual router behind a tun network interface. It's a little harder to set up, but it does make everything go through the SOCKS proxy. The following guide explains how to use tun2socks with a SOCKS proxy provided by the SSH -D option, but you should just ignore all it says about SSH and just specify your SOCKS proxy. http://code.google.com/p/badvpn/wiki/tun2socks

If, on the other hand, the proxy server is only HTTP, the situation is much harder. If you're lucky, your HTTP proxy supports the CONNECT command, and you can use that to connect to the SSH server. If the proxy is limiting the CONNECT command to specific port numbers, you will have to change the port number your SSH server is listening on to one allowed by the HTTP proxy.

One piece of software you can use for that is ProxyTunnel: http://proxytunnel.sourceforge.net/intro.php

But, what if you have to but can't change the listening port of the SSH server (or want to connect to anything not just your SSH server)? In that case the only solution is to go through an intermediate server which you have full control over. So, then connect to that intermediate server with SSH (via ProxyTunnel). Then you can:

  • either use SSH's dynamic forwarding (-D) option (which opens a local SOCKS server on the client), and get your scp through this SOCKS interface using tsocks or tun2socks, as described above, or,
  • set up a real IP VPN between your computer and the the intermediate server you managed to connect to (see ssh -w option)
  • I added a link for tun2socks – sleske Jul 18 '11 at 12:58
  • corkscrew will tunnel ssh through an http proxy and is dead easy to setup. – Sirex Jul 18 '11 at 14:10

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.