How to get shell on your Android phone from Ubuntu

If it’s Linux, you should be able to telnet/ssh to it, right? So yes, Android does have a shell (albeit really limited), which you can access from the phone by installing a terminat app. If you want to type from a real keyboard and you want to be able to copy-paste commands from the net, you can also “telnet” to the device from your computer, by plugging in the USB cable and following some pretty simple steps.

Step 1. Get the Android SDK. Don’t worry, you don’t need to know how to code, you just need one program which comes with the SDK: adb (Android Debugging Bridge). You are going to download and unpack it. Note that you can get the link for new versions (when they will be available), on the SDK download page.

$ cd /some/dir
$ wget http://dl.google.com/android/android-sdk_r07-linux_x86.tgz
$ tar xvzf android-sdk_r07-linux_x86.tgz
$ cd android-sdk-linux_x86/tools

You should now be in the tools directory, which contains the adb tool.

Step 2. Set your phone in USB Debugging mode. On your phone, go to Settings > Applications > Development and tick the USB Debugging box. Confirm.

Step 3. Connect the phone to the computer with the USB cable. When prompted, select Charge only. In USB disk mode, the SD card is no longer available to the phone itsself so you’ll not be able to access /sdcard.

Step 4. Telnet to the device with adb.

$ ./adb kill-server
$ ./adb shell

If you got the shell prompt

$

… you’re good to go, so skip directly to step 6.

If instead of the comand prompt, you get something like this:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: device not found

…then udev didn’t create the device files properly. You will need to do the next step too.

Step 5 (optional). Create udev rules. Download my 51-android.rules, which you should place in /etc/udev/rules.d . It contains the information that udev needs in order to create the devices for known Android devices. A complete list of vendor IDs is here. If my file is not working for you (it’s tested on Ubuntu 10.4), check out the list and do the proper changes/updates.

$ cd /my/download/location
$ sudo mv 51-android.rules /etc/udev.d/rules.d
$ sudo restart udev
$ cd /location/of/android-sdk/tools

You should unplug/replug the USB cable and return to step 3.

Step 6. Hack the Droid! You can now poke around to check how the Android system is build. Some usual commands work (mv, ps, cat, mount, cd, mkdir, rm and so on). cp is, strangely, missing, but cat > file works. And if you have a rooted phone (I used Unrevoked 3, which worked beautifully, unattended), the first command you’ll want to run after you connect to the phone’s shell is:

$ su -
#

And now all the fun starts :D . Enjoy and let me know if it works for you!

Image credit: laihiuyeung ryanne.

TwitterFacebookLinkedInGoogle ReaderYahoo MessengerEmailGoogle GmailYahoo MailPrintShare

No related posts.

2 comments

  1. [...] How to get shell on your Android phone from Ubuntu If it’s Linux, you should be able to telnet/ssh to it, right? So yes, Android does have a shell (albeit really limited), which you can access from the phone by installing a terminat app. If you want to type from a real keyboard and you want to be able to copy-paste commands from the net, you can also “telnet” to the device from your computer, by plugging in the USB cable and following some pretty simple steps. [...]

  2. [...] you used my previous tutorial on how to get shell on your Android phone from Ubuntu, you might have noticed that starting with SDK version 8, the adb tool is no longer in the tools [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*


4 − two =

CommentLuv badge