Port forwarding over SSH to an Android Thing(s)

I was a bit frustrated on this one, because even if the commands are fairly easy, the results are hard to debug when they show up.

I wanted to be able to connect to my Android Things RPi3 device over SSH. This is pretty much simple port forwarding shenanigans but I got stuck for it for about an hour.

My computer setup looks somewhat like this

 ____________
|            |
| Computer 1 |
| (client)   |
|____________|
      |
      | Interwebs
      |
 _____________
|             |
| Computer 2  |
| (server)    |
| port: 2222  |
|_____________|
      B
      B Wifi
      B
 ____________
|            |
| RPi 3      |
| (Android)  |
| port: 5555 |
|____________|

The command to make this work is

ssh -L 2223:[ip of RPi3]:5555 [user name to server]@[host name/ip of server] -p 2222

What this does is create a local port, 2223, on Computer 1 that connects to the ip of the RPi3 on port 5555, through the server using port 2222.

After this command is executed you will have to use your password to log in on your server, and it will end up at a console prompt. Open a new terminal window on Computer 1 and execute the following

adb connect localhost:2223

This will tell adb on Computer 1 to attempt a connection to itself, localhost, on port 2223, which is the one we created in the step above. This will automatically trigger that connection attempt to pass through the SSH tunnel and talk to the RPi3.

You should see your device being connected on Computer 1 through

adb devices

…and you should be good to go with monitoring, developing, or whatever you fancy, through adb.

Thanks to Otyg over at #sis on IRC

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>