Friday, May 6, 2011

ssh -D <port> <username@server.com>; but in reverse?

Is it possible to set up an SSH tunnel with dynamic port forwarding like this:

ssh -D username@server.com

but do it the other way around? That's to say I want to initiate the connection on my local machine and have the dynamic port forwarding happen there, and have my friend connect his browser to the other end of the tunnel.

The above works perfectly if my friend types the above but I don't want to give him ssh access to my machine, just let him proxy his browser though it.

From stackoverflow
  • For openssh, see the -R switch:

     -R [bind_address:]port:host:hostport
             Specifies that the given port on the remote (server) host is to
             be forwarded to the given host and port on the local side.  This
             works by allocating a socket to listen to port on the remote
             side, and whenever a connection is made to this port, the connec‐
             tion is forwarded over the secure channel, and a connection is
             made to host port hostport from the local machine.
    

    Though there may be better solutions, you could create a SOCKS proxy at your friend's computer remotehost at port 24680 in the following manner. First, do

    ssh -R 24680:localhost:12345 remotehost
    

    And then, do

    ssh -D 12345 localhost
    

    Obviously, both sessions need to be kept alive simultaneously.

0 comments:

Post a Comment