I wanted to use rsync / ssh combination to do a backup of a phone that I don’t want to root. There were few problems:

a) the rsync4android failed with an error that said: ‘ssh: exiting: string is too long’:

2015-05-03 14.22.38

b) other solutions meant being root.

I’ve decided to cross-compile openssh-5.8p2 (which came with my busybox) so that I can use it in a combination with rsync (which I’ve also cross compiled) and all controlled by GScript (this will be a topic of a separate post).

The troubles encountered with getting openssh to run are that there’s no luck for the getpw* methods in Android (as /etc/passwd doesn’t exist and thus they return null. Just executing ssh on the phone produced the error: “You don’t exist, go away!”

I’ve tracked this down into ssh.c file:

Just patching this line doesn’t work, since there will be segmentation faults and other calls to getpwuid

I’ve created a small patch that addresses this issue:

What it does is that it introduces a fake getpwuid method (called vi_getpwuid) which returns a valid passwd struct but filled with fake data (I haven’t investigated the security risks linked to this – I just wanted to get the code running). It assumes the username is ‘android’ (the username is in fact the application id, but I haven’t studied how to retrieve that from the NDK layer).
It also assumes the user home dir to be /sdcard (where ssh will create the .ssh/known_hosts file.

By trial and error, I found 3 places where the changes had to be done to get ssh to work via rsync: there were two checks in ssh.c file and one more in misc.c itself inside the tilde_expand_filename method. This too had to be fixed, otherwise ssh would complain with:

Hope this helps!