Sunday, July 2, 2017

Ubuntu - Copy large number of files easily to Android Phone

Situation:

The MTP protocol for transferring files to and from an Android Phone is utter garbage, especially when transferring a large number of files (like your Music collection for the first time - on my Google Pixel). The connection inevitably fails in the middle of the transfer, which is slow to boot.

Solution:

USB tether your phone to your computer (read http://abidmujtaba.blogspot.com/2017/07/ubuntu-usb-tethering-with-google-pixel.html if you get stuck). You don't even need internet pass-through, just an IP Address (so you can use sudo dhclient usb0 instead of sudo dhcpcd usb0 if you are using the terminal).

Next follow http://abidmujtaba.blogspot.com/2017/07/ubuntu-ssh-in-to-android-phone-google.html to set up an ssh connection. Once you have that you are home free.

I use lftp over ssh to copy all the files I want. I even have a simple lftp bookmark set up:
pixel sftp://abid:xx@pixel
where my ssh config section is titled "pixel" and the password "xx" is just a red-herring since ssh is configured to use an RSA key for authentication. This bookmark allows me to access my phone's files using a simple lftp pixel.

Ubuntu - SSH in to Android Phone (Google Pixel)

The ability to SSH in to your (unrooted) Android Phone is a very powerful one to have, and it is surprisingly simple.


  1. Install the "SimpleSSHD" app on your phone (form the Google Play Store).
  2. Copy your PUBLIC ssh key (form your computer) to the "/sdcard/ssh" (default) folder on your phone and rename it authorized_keys.
  3. Run the "SimpleSSHD" app and click start (uses port 2222 be default since it runs in user space). The app will tell you the IP address of the phone.
  4. SSH in to your phone by issuing:
    ssh -o StrictHostKeyChecking=no -p 2222 -i <private key location> <phone ip address>
    You will need to issue StrictHostKeyChecking=no the first time only.
  5. To avoid having to type all of this out every time you can add a section to the ssh config file (~/.ssh/config).
    Host pixel
    
        Hostname 192.168.42.129
        Port 2222
        IdentityFile ~/.ssh/pixel
    
    and simply run ssh pixel to connect.
Nore: This technique works with USB tethering as well. SimpleSSHD will show both the WiFi and the USB Tethering IP Addresses and you can use the latter for super-fast ssh.

Ubuntu - USB Tethering with the Google Pixel

Situation:

When I connected my Google Pixel to my Ubuntu (14.04) laptop with the USB cable and selected the option to USB tether on the phone the connection would fail. The Network Manager applet would show a greyed out option "Ethernet Network (Google Pixel)" with the status "disconnected" underneath it, also greyed out.

Interestingly running "ifconfig" revealed that a "usb0" section was present but no IP address had been assigned.
usb0      Link encap:Ethernet  HWaddr 32:a8:e6:6c:fe:9d  
          inet6 addr: fe80::30a8:e6ff:fe6c:fe9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:560 (560.0 B)  TX bytes:1802 (1.8 KB)

This clue led to a long trawl across the internet that led to a surprisingly simple solution.

Solution:

Install the "dhcpcd" package.
sudo apt-get install dhcpcd
Now after connecting the Google Pixel simply run:
sudo dhcpcd usb0
And confirm by running:
ifconfig usb0
route -n
ping -c3 www.google.com