A simple tunnel is more usually done as
ssh -L 8080:localhost:80 myUsername@remoteserver.com
- -L = local port forward, ie from where I am to where I'm going
- 8080 = port on this machine to forward. The port my browser will connect to as http://localhost:8080
- localhost = The destination on the remote server, in this case itself.
- 80 = Port on the remote (target) machine to connect to, the port where the service is running.
This would allow you to access the web server on the remote server, when you have ssh access to it, but do not have web access to it.
ssh'ing to your localhost is usually pointless. It is only done to check your ssh server is running properly or keys are correct.
The connection refused error you see is because ssh server is not running on your local machine. sudo apt-get install openssh-server Then you can ssh to your local machine from localhost, or anywhere else you can get a port 22 connection to this machine from (typically behind your local network firewall)
-D (dynamic application forwarding) is a different case, and would more apply if some tricky fat client application (eg mysql) on your local machine needs to access a server on a remote machine. It is less often used.
The message about privileged ports occurs when you try to redirect a local port less than 1024. Hence the use of port 8080 in the above example, to avoid the priviledged port 80. For the example above, your browser would use