5

So I have an Android smartphone (Samsung Galaxy S5) and I would like to figure out if I can connect it over USB to my laptop running Ubuntu and then control the laptop over SSH and USB rather than over SSH and WiFi.

Is it possible and if so how can I do it?

4
  • You can download several apps from playstore in order to get an ssh connection without a USB. Apr 22, 2017 at 2:24
  • Termux is decent.
    – wjandrea
    Apr 22, 2017 at 3:15
  • But I don't want to use wi-fi because it's not my router. Please read the question. I want to use USB. Of course, if you know some way to do this without either wi-fi or USB I'm also interested but otherwise I need a solution that works over USB. If it could be done with Termux that would be cool because I like Termux. @wjandrea
    – Vesa
    Apr 22, 2017 at 11:04
  • @user654662 Please read my comment above
    – Vesa
    Apr 22, 2017 at 11:06

2 Answers 2

6

I don't know how really this question is related with Ubuntu, but it is fun and I will write an answer.


I have a phone with Android 4.4.4 and often use these tools:


How to connect Android device over USB to SSH into a laptop running Ubuntu

1. Open HotSpot app, go to USB tab and enable USB network sharing. We don't need the connected device to use mobile data over USB, but this option will prepare virtual network that we will use.

2. Open Network Discovery app, go to Settings menuDiscoveryDiscover MethodPing/c.... Go back to home screen and tap on Discover. When this process finishes copy the IP of the target network device. There shall be only one device.

enter image description here

enter image description here

3. Open ConnectBot and setup your SSH key if it is needed (tap on the menu in upper right corner).

4. Setup a new connection - use the discovered IP, and tap on + ADD HOST to save.

5. Go back to the ConnectBot home screen, tap on the new connection and use it.

enter image description here

enter image description here


Additionally if your Ubuntu has GUI and properly configured VNC server, you can setup port forwarding for ConnectBot's connection and can use RealVNC Viewer to connect with your desktop. Pocket Bluetooth keyboard and mouse make things really nice.

enter image description here

17
  • Looks interesting and I want to test this. But the "embedded hotspot app" is not available on my device. How can I turn on USB network sharing?
    – Vesa
    Apr 23, 2017 at 3:02
  • I have followed your instructions and the mobile phone is connected with USB to the laptop and ping is chosen in the Network Discovery settings but the app does not seem to find the IP address. It just says "obtaining ip address from unknown SSID" and the discovery button has a red warning sign and cannot be clicked.
    – Vesa
    Apr 23, 2017 at 3:25
  • @Vesa, the other name of this functionality is "USB Tethering". For your device follow this manual. The USB cable must be plugged in, to be USB Tethering available. Also WiFi HotSpot is another option to create private network
    – pa4080
    Apr 23, 2017 at 10:07
  • Yes, I figured that out but I was still not able to connect yesterday. I think I had the right IP and I tried to connect with Juicy SSH but it just said connecting but nothing happened. Network Discovery wasn't working so I got the IP with Termux/Ifconfig. Still something not right though.
    – Vesa
    Apr 23, 2017 at 23:55
  • I tried again today. Same problem. JuiceSSH just says connecting without actually doing so. Should port number still be 22 when using USB or something else?
    – Vesa
    Apr 24, 2017 at 0:18
4

You can use adb reverse, for example direct your phone's port 8080 to laptop's port 22 by adb reverse tcp:8080 tcp:22, then do ssh [email protected] -p 8080 from your phone.

I think this is a better solution since no virtual network or IP detecting is needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .