Reverse/Forward SSH

Reverse/Forward SSH allow to bind a port on a host reachable by the local host to a port on the remote host, or to bind a port on a host reachable by the remote host on the local host. All communication done on one side will automatically reach the other side, through a SSH encrypted tunnel.

Note: only superuser can forward privileged ports.

Common options

With these command some ssh options are commonly used:

Reverse ssh

Bind remote port to a local-side host and port. When a connection is made on the remote port, it is forwarded to the local host, and then the local host will made the connection to the local-side host.

ssh -TNf -R [{bind address}:]{remote port}:{local-side host}:{port on local-side host} username@{remote machine}

Forward ssh

Bind local port to a remote-side host and port. When a connection is made on the local port, it is forwarded to the remote host, and then the remote host will made the connection to the remote-side host.

ssh -TNf -L [{bind address}:]{local port}:{remote-side host}:{port on remote-side host} username@{remote machine}

SOCKS proxy

The ssh client can act locally as a SOCKS http proxy (the most common protocol used for http proxies).

ssh -TNf -D [{bind address}:]{local port} {username}@{remote machine}

Keep connection open: autossh

After a while, ssh connections close automatically. This can be extended by setting certain properties on the server, but it will eventually happen. To keep a tunnel alive, you can use autossh. It will launch a ssh process, and restart it when it dies.

Listen on other address than 127.0.0.1

By default the socket created to listen for incoming connection (both in forward and reverse mode) is bound to 127.0.0.1 as a security measure. If you want to bind to a different address (e.g. '*'), you need to: