Is it possible to connect a rooted Android device to a RPI via USB and then SSH into the RPI from the Android device over the USB connection? If so is there any documents or tutorials out there that outline this? I've done it from wireless several times but I would like to achieve the SSH connection over the USB cable.
5 Answers
You could do that, using android's USB tethering. On android 4 this option should be at settings>more>Tethering and portable hotspot>USB tethering
(option becomes enabled when you plug the USB to the PI).
Then you need to set up your PI for this:
1) add the following to /etc/network/interfaces:
auto eth0
iface eth0 inet dhcp
iface usb0 inet dchp
2) and execute the following command:
ifup usb0
Confirm your connection is up via ifconfig
-
Thanks for the info! I will try this out over the weekend and get back to ya. I want to be able to use my RPI on the fly and keep wireless available to my RPI for other purposes. Thanks!– 0xhughesCommented Jun 7, 2013 at 13:03
-
Sorry for the extreme delay! I was succesfully able to implement this! It was really slick, been using it for months!– 0xhughesCommented Dec 31, 2013 at 22:20
Most likely it's impossible. You'll need "Linux USB Ethernet/RNDIS Gadget" driver installed on Android for that, and I'm pretty sure this driver is not included in the standard Android package.
Using a wireless connection would be much easier.
-
Voted this up, because he is right, but then thought of a way around this.– GuySoftCommented Jun 7, 2013 at 11:09
-
No, this posting makes an invalid assumption that there is only one way to do it. Commented Nov 19, 2015 at 18:18
-
It is possible. I do it all the time with my Pi A+ using Termius on Android.– TooniisCommented Oct 5, 2018 at 12:07
Not all the Android devices support USB tethering. If it's available on you device, go for it. Otherwise, you can use an ADB client installed on the Raspberry PI, then using some port forwarding you can make the Android tablet and the Raspberry Pi talk on USB.
@GuySoft answer needs to be updated based on Raspian Jessie from this answer:
DO NOT MODIFY /etc/network/interfaces
Add the following to the end of /etc/dhcpcd.conf
interface usb0
static ip_address=192.168.42.42/24
static routers=192.168.42.1
static domain_name_servers=8.8.8.8
routers and domain_name_servers line may not be necessary
-
192.168.42.42/24
is NOT in the same subnet as192.168.44.1
so your network setting WILL NOT WORK. Your RPi at 192.168.42.42 won't be able to find the router at 192.168.44.1.– DougieCommented Jul 27, 2019 at 13:47 -
-
This worked for me, although I also had to add this line to
/etc/network/interfaces
:iface usb0 inet dhcp
.– swrefCommented Nov 18, 2019 at 14:59 -
@swref I was using static addresses, was that the only change you needed to make to use DHCP?– MikeFCommented Nov 19, 2019 at 3:28
You might want to read my answer here. It describes how to connect to ssh using USB tethering and your Pi. Bonus: you can even add android's WiFi hotspot to that solution and connect more devices.
If that's not enough, you can use adb to forward your SSH port with adb forward <local> <remote>
and adb reverse <remote> <local>
From my experience, you will need a recent adb build, which you'll have to compile yourself as described in my answer here.