« Optimistic Fair Contract Signing for Web Services | Main | Remote Access to Department Computer Resources »

SSH Port-forwarding

SSH has a function to forward arbitrary TCP/IP ports over the secure secure channel. There are thousands of documents on how it works. (eg. an easy tutorial in ssh.com is found here)

Here I focus on how to use it on PC. All you need is a SSH client which supports port forwarding. OpenSSH is a free version of SSH implementation, primarily for BSD and other Unix-style platforms. Cygwin, a collection of Linux-like tools for Windows, provides the OpenSSH binary that works on Windows, so I assume the use of OpenSSH.

OpenSSH is a nice old-fashioned text-based program. There are a lot of GUI ssh clients for Windows: ttssh, putty, etc. I believe many of they them support port forwarding, although I don't know much about them.

Using OpenSSH, you can do remote login with the following command.


$ ssh (your username)@(remote hostname)

Then you are usually asked a password (or a passphrase).

On the other hand, when you use port-forwarding, you need to add -L option.


$ ssh -L xxxx:(third hostname):yyyy (your username)@(remote hostname)

Here, xxxx and yyyy are digits to describe port numbers. As a result, the following happens.

- If a program on your PC accesses localhost:xxxx, ssh forwards it to (third hostname):yyyy. By default, only a local program can connect to localhost:xxxx.
- When the program on the (third host) accepts the access, it recognizes that this connection came from the remote host, not your PC.

Note that the communication between the (remote host) and the (third host) is not secure.