I've written before about using ssh tunnels to access servers
behind a firewall, but recently I've been amazed again by the utility
of ssh tunnels.
To access a web server behind a firewall, the ssh client running on
the computer you are sitting at listens on a given port number, and
the ssh server on the machine you connect to connects to a given host
and port. Any connection made to the port on the local machine is
captured by ssh and forwarded to the machine the ssh server has
connected to. The -L switch accomplishes this, so for a command line
like ssh -L 6789:192.168.3.134:80 remote.machine.com, the ssh
client listens on port 6789, and the ssh server on remote.machine.com
forwards connections to 192.168.3.134:80, which is some machine inside
a private network. Now pointing your web browser at
http://localhost:6789/ connects you to 192.168.3.134:80.
I recently had to help a friend with a problem they were having,
and I wanted to ssh into thier machine so I could see what was going
on. Unfortunatly, their machine is behind a firewall, and they didn't
have the passwords to open a port. Tunnels to the rescue! I created an
account for my friend on spacemonkeys.ca, so that they could ssh
in. Thier machine was running an ssh server already, so they used this
command to log in to spacemonkeys.ca: ssh -R 6789:localhost:22
spacemonkeys.ca. This opens port 6789 on spacemonkeys.ca, and
forwards any connections to the ssh port on my friends firewalled
computer. I could then ssh into thier machine from spacemonkeys.ca:
ssh -p 6789 localhost.
Pretty spiffy!