Connecting Through SSH SOCKS Proxy on Linux or Mac OS X

2010-06-23

Problem

You work for a client that provides you with a connection to transfer files over SSH (SFTP). He wants to adjust the corporate firewall settings so that requests from your IP address don't get rejected. The problem is that you work from different places with different IP addresses. It would be time-consuming to add all the different addresses and modify them every time one of them changes. But you also have a server without a GUI but with a static IP address accessible from all the different places you work from.

Solution

Use SSHs ability to create a SOCKS Proxy and only the IP address of your server has to be added to the firewall rules.

To do so execute the command ssh -D 2432 myserver.example.com from the command line.

The -D flag enables this kind of port forwarding. It is followed by the port you want to listen to locally. Now you have to use an SFTP client that allows to specify a SOCKS proxy. To name two common applications, Filezilla (multiple platforms) and Transmit (Mac OS X) are both able to do so. The corresponding Transmit dialog box is shown below.

Everything connecting to this port is now forwarded over the ssh connection. If you don't need the command prompt of your server add the -nflag to the ssh command to start the connection completely in background.

Post to Twitter