Use server's IP via SSH tunnel

What you want is not a reverse tunnel but a regular tunnel.

ssh -L 80:someserver.com:80 user@myserver

This will create a listening socket on port 80 of your laptop (localhost) that will go to someserver.com through the SSH server on myserver.

I usually combine tunnels with the options -CfN, -C will enable compression (speeds things up a bit), -f sends the SSH to the background once the authentication is complete (so you still have a chance to enter the password if needed), -N will make sure no command is executed on the SSH server (it's not really safe to have an SSH running in the background that could hypothetically be used send commands to the server, it's a bit of healthy paranoia/a good practice).

If you don't care about having a very secure connection between your laptop and myserver, you can also change the cipher to something fast, like blowfish using -c blowfish, or arcfour128 (which is faster still).

So what I would use is this:

ssh -CfNc arcfour128 -L 80:someserver.com:80 user@myserver

Which will give you nice, fast tunnel that goes straight into the background instead of leaving an open command prompt on your server.

Keep in mind that if you send it to the background, when you want to break the tunnel, you'll have to first find the process id by doing something like ps -ef | grep ssh and kill the correct process id.


You could use the SOCKS proxy that ssh provides. Connect via

ssh -D 9999 user@myserver

and then you could use this SOCKS proxy in your python script as described in How can I use a SOCKS 4/5 proxy with urllib2:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9999)
socket.socket = socks.socksocket

(Put this code at the top of your script)