Access Ports Through SSH

Want to access your http server or remote destop of a machine you have SSH access to, which out making the ports public or playing with VPNs?

A quick way to access a port on a remote machine from the local machine and vice versa through SSH

To access a service running on a remote machine

ssh -L local_port:remote_address:remote_port user@remote.server.com -N 

Now the remote service is available securely at localhost:local_port through SSH. Where -N prevents the execution of a remote command. This is useful for just forwarding ports.

For example to access a remote VNC server, do the following:

ssh -L 5900:localhost:5900 user@remote.server.com -N 

To access a local service from a remote machine

ssh -R remote_port:local_address:local_port user@remote.server.com

Now the local service is available securely at remote_port on the remote machine through SSH.

For example, to access an http server running on a local machine from the remote machine’s port 8080, do the following:

ssh -R 8080:localhost:80 user@remote.server.com