Question

I managed to initiate Linux on my Android phone through the terminal and even start the SSH service and tested it using ConnectBot. However, this is a manual operation. I was thinking more of an automated way of doing this.

I used this Linux mechanism: http://mitchtech.net/android-backtrack-chroot/

My main issue I believe is that I'm trying to do some steps before and after chroot is done, which didn't seem to work on an Android app:

Runtime.getRuntime().exec("su");

//Mount the image
Runtime.getRuntime().exec("startbt");

//chroot into Linux
Runtime.getRuntime().exec("bt");

//From inside chroot, start the ssh service
Runtime.getRuntime().exec("/etc/init.d/ssh start");

This also did not seem to work:

Runtime.getRuntime().exec("su & startbt & bt & /etc/init.d/ssh start");

I'm guessing again this is an issue what is interpreted as inside or outside the chroot. My main quest eventually is to start the SSH service automatically, not necessarily through an Android app.

Was it helpful?

Solution

If you execute

Runtime.getRuntime().exec("su");

this will just launch su and then exit. The next exec won't be executed with elevated privileges. Likewise after executing bt the next command isn't executed within the chroot environment.

I presume bt is a script? You could change it to pass arguments to chroot, so you can pass it the command to execute, something like:

...
chroot new_root /etc/init.d/ssh start
...

To run this, you need to pass the command to su directly using the -c option. And you need to pass the commands as String array (or use a ProcessBuilder):

Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt"});

Another option would be to make bt pass arguments from the command line to chroot:

chroot new_root "$@"

and then pass them on the command line:

Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt /etc/init.d/ssh start"});

OTHER TIPS

Unless you really want to do things this way, I'd honestly just download an SSH server app.

I personally use SSHDroid.

https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en

But from the looks of things you're building your own app to start the built-in ssh server yourself? So you probably already know that you could already just do it using an app.

Good luck anyways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top