Reverse SSH Tunnel
2010-08-22 Leave a Comment
Just finished playing around with reverse SSH tunnels with my buddy jkit so I figured I’d write this stuff down before I forgot.
ssh -nNT -R 1199:localhost:22 remotehost.com
This command looks pretty confusing if it’s the first time you’re seeing it (at least it did to me), but an intuitive way to phrase it would be: map port 1199 to localhost:22 on remotehost.com.
What’s the use case? For one, this command would allow you to SSH into a machine that is on a network behind a firewall or a router that you don’t have configuration access to. For example, if you’re on your laptop at a random cafe and you want to share a screen session on localhost, the other person would need SSH access.
What the above command would do is allow that person to SSH into your laptop from remotehost.com like so:
ssh -p1199 localhost
If you’re interested in other interesting use cases, check out localtunnel!