It’s called a reverse SSH tunnel
And it’s used to keep a link from a device that may be behind a firewall. Or perhaps it’s connected to a highly variable mobile network. When it’s opened, it allows users to “tunnel” through the connection, to wherever the device might be.
Here’s what I put into the shell script “tunnel”, on my iPhone’s ~/mobile directory:
#!/bin/sh
ssh -R 8022:localhost:22 -f -N mpesce@webearth.org
That fairly simple line opens a connection via port 8022 on webearth.org (which sits underneath my telly), to port 22 (which is the normal SSH port) on my iPhone. Thus, if I go to the command line on webearth.org and type the following:
ssh -p 8022 mobile@localhost
Voila, I have a shell into my iPhone.
Yes, those of you who are not serious network geeks, this seems like rocket science. It’s not. Reverse SSH tunnels are used all the time by folks behind, say, the Great Firewall of China, or simply the NSW Public Schools network.
Update: I’ve realized that SSH, as a security precaution, will shut down open connections if they’re not used. In ~/mobile/.ssh, create a new file named config, and put the following line in the file:
ServerAliveInterval 60
That should keep things connected indefinitely.
Tags: BSD, hack, iPhone, networking, SSH, tunnel
This entry was posted on Saturday, August 2nd, 2008 at 11:58 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
August 2nd, 2008 at 11:10 pm
I just saw you call for routed guru’s on Twitter.
I can work with you to expain or figure it out for you
The goal is how to make a wifi and bluetooth hotspot out of the iPhone, including thetering?
Happy to help, just ask
August 3rd, 2008 at 10:53 am
thx 4 the post, nice, easy and simple
August 19th, 2008 at 1:09 am
See more tricks in guides below to tether the iphone and get it online via USB cable
http://alk2blog.blogspot.com
November 6th, 2008 at 11:15 pm
I would like to Tunnel a port over SSH from the iPhone and turn back to Jaadu VNC without closing the tunnel. Is there any possibility to do that?
As u know when i press the home button, the app closes
Thanks
December 20th, 2009 at 3:21 am
islam adel,
Terminal on the iPhone will stay OPEN by default, unless you have backgrounder installed, in which case you would need to hold down the home button to close MobileTerminal…
jaadu VNC and RDP both support SSH protocol now.. but i still use terminal to tunnel, then use jaadu to connect to localhost of iphone on port forwarded to…
you can actually use reverse ssh to control your iphone no matter where it goes… a bootup script and auto-ssh is needed to maintain connection