SSH server on Android - remote access to your green robot device

Check out the new site at https://rkblog.dev.

You can login via SSH on a server. You can do that also for an Android device - phone, tablet or a HDMI/TV Android dongle. Just install a SSH server and you can connect to your device using SSH or SFTP - transfer files or execute commands from the shell. In this article I'll go through installing one of SSH servers on Android and using SSH connection to do handy things on the device.

Installing SSH server on Android

There are multiple applications providing a SSH server, for example SSHDroid (used in this article), SSH Server, or Ssh server and so on. You don't need root to use most of them, but if you have it you will be able to login as root via SSH.

In case of SSHDroid the setup is easy. You even get an introduction at first start:

Introduction at first start

SSHDroid gives you a quick introduction at first start

Asking for root permissions

If you have root access then you can grant it to the application too

SSH server is ready and running

When the server is running you see the login and internal IP of the device to which you want to SSH

The default password is "admin" and it will be also printed out when you will try to connect via SSH. You can use the same credentials to connect via SFTP and manage files on the device.

SFTP connection with an Android device

Managing files on Android device over a network with a SFTP connection

Android from the terminal

If you know Bash and working with Linux from the terminal then you will feel quite comfortably with the shell on Android. You can do stuff like top, free or df to see what's going on the device. You also have the Android specific tools like adb and am.

The am command can start applications but you have to know the application name and it intent name that you want to start. The command looks like so:

am start -a android.intent.action.VIEW -n APP_NAME/INTENT_NAME.
For example to start Google Chrome with a given webpage URL you would have to execute:
am start -a android.intent.action.VIEW -n com.android.chrome/.Main -d http://www.rk.edu.pl
To start Android settings application:
am start -a android.intent.action.VIEW -n com.android.settings/.Settings

You can get application name from the application description (usually, depending on Android flavor) in settings. Intents are harder to get. If you are lucky they will be in some documentation or in the source code. If not, you have to take a look at the application APK file and for example - analyze APK manifest (described on wrla.ch blog).

Python from the terminal

SL4A - scripting languages for Android offer Python runtime - from Py4A or QPython packages. Using a very long command you can execute a Python script from the terminal:

am start -a com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/hello_world.py

More on code.google.com/p/android-scripting/.

RkBlog

Check out the new site at https://rkblog.dev.
Comment article
Comment article RkBlog main page Search RSS Contact