The next thing on my list was to set up a SSH server and to be able to transfer files between my Linux system and my phone (by the way, I’m running Android 4.1 and it seems USB mass storage support has been removed. MTP/PTP modes have either horrible transfer speed or are poorly supported in Ubuntu).
With the above in mind, the plan was to:
- Enable tethering on the phone
- Run a SSH server to support issuing remote commands and file transfer (FTP might have been an alternative, but I’m a SSH adept).
Browsing the market I found SSHDroid which does all that it advertised. Problem is – the free version conflicts with my add-blocking apps and requests that they are disabled to run.
For me, this is a big nuisance, so I kept looking. I found Dropbear SSH Server 2, which is completely free, but doesn’t support scp/sftp.
So, I wanted scp/sftp support, so I started to work on a solution.
If, after starting Dropbear server you try to transfer a file via scp you get this error (pris is the name of my phone and is mapped to an IP address via the /etc/hosts file):
then, you are in the same situation I was…
For scp/sftp to work, the process needs to have access to the scp/sftp-server binaries on your android system. But it seems dropbear doesn’t come with those binaries. But searching around the system, the binaries are available in the SSHDroid package.
So, I was doing the following steps to make those binaries available to the whole system (needs a rooted system with busybox installed):
[email protected]:/data/local # scp
sh: scp: not found
127|[email protected]:/data/local # find / -name scp 2>/dev/null
1|[email protected]:/data/local # /data/data/berserker.android.apps.sshdroid/dropbear/scp
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[[email protected]]host1:]file1 […] [[[email protected]]host2:]file2
1|[email protected]:/data/local # ls -l /system/xbin/
-rwxr-xr-x root shell 59760 2012-09-28 12:15 dexdump
-rwsr-sr-x root root 91992 2012-12-21 10:02 su
[email protected]:/data/local # echo $PATH
[email protected]:/data/local # mount -o remount,rw /system
[email protected]:/data/local # ln -s /data/data/berserker.android.apps.sshdroid/dropbear/scp /system/xbin/scp
[email protected]:/data/local # ln -s /data/data/berserker.android.apps.sshdroid/dropbear/ssh /system/xbin/ssh
[email protected]:/data/local # ln -s /data/data/berserker.android.apps.sshdroid/dropbear/sftp-server /system/xbin/sftp-server
[email protected]:/data/local # mount -o remount,ro /system
At this point, you can use scp to transfer files from your computer to your Android device. However, you can’t mount it with sshfs yet.
The problem when mounting it is that sshfs tries to use the sftp server, and by default it tries to call it from /usr/libexec/sftp-server. This path does not exist on your android device, and you will need to instruct sftp to use /system/xbin/sftp-server instead. You can do this with the following command:
sudo sshfs -o sftp_server=/system/xbin/sftp-server [email protected]:/storage /media/pris
Of course, in order to mount the device as a regular user and to be able to transfer files, you will need to prepare your mount point and your fstab entry:
[email protected]:~/temp$ sudo mkdir -p /media/pris
[email protected]:~/temp$ sudo chown root:fuse /media/pris
[email protected]:~/temp$ sudo chmod g+w /media/pris
[email protected]:~/temp$ cat /etc/fstab | grep pris
sshfs#[email protected]:/storage /media/pris fuse user,fsname=sshfs#[email protected]:/storage,noauto,sftp_server=/system/xbin/sftp-server 0 0
You will now be able to mount the device via the command line (or in Nautilus). It will ask for your ssh password, and then it will display the files as if they were local. In terms of performance, I get about 4.6MB/s reads and 4.1MB/s write speed (over USB). Compared to ~240kB/s read/write in MTP mode, I would say I get quite a performance boost!
Remember, in order to follow the steps above you will need:
- a rooted android device
- busybox installed
- SSHDroid installed (it will remain installed even if you don’t start the ssh service. You can possibly uninstall it if you replace the “ln -s” commands with “cp” instead)
- Dropbear II (and started)
- either a wifi connection between your PC and android device, or USB tethering (it’s what I’m using)