Monday, February 13, 2012

SSH local port forwarding

Recently I advised on serverfault.com how to do local port forwarding with ssh:

On remote machine with sshd server, start a service that you would like to give access to:
 echo "hello" | nc -l -p 2222
On local machine initiate port forwarding:
 ssh -L 1234:localhost:2222 root@remoteserver.com
try it (from local machine):
 nc localhost 1234
If you will see "hello" that means port forwarding worked as expected.

 Use cases for this kind of functionality:
 - tunneling otherwise insecure TCP traffic
 - accessing services behind firewall when only sshd access is available