Telnet is lame so we will have a look at setting up dropbear as sshd on Android. This how-to will show you how to install configure and run dropbear as sshd and how to connect with a ssh client.
A dropbear built from the original sources won't run properly on Android; the reason is that Android has no proper user support (/etc/passwd).
There are two solutions for getting the proper changes to the sources:
Once the sources are fixed you now need to crosscompile them. This requires a cross compiler to be setup (this process is not covered here).
The cross compilation and build goes like this:
./configure --host=arm-none-linux-gnueabi --disable-zlib make CC=arm-none-linux-gnueabi-gcc
Once built the output is following 3 binaries:
The installation is quite simple: copy the binaries to your favorite dir to android, e.g. /sdcard
First we need a server key. Keys are generated using dropbearkey. To generate a RSA server key:
dropbearkey -t rsa -f dropbear_rsa_host_key
Now create a dir /data/dropbear and copy dropbear_rsa_host_key there.
Test dropbear:
/sdcard/dropbear -r dropbear_rsa_host_key -F -E -v -s
This should show you the debuglog of dropbear starting in non-daemon mode (-F).
Now we need to generate a key/pair for the client to connect with (theoretically the client can connect using password but as stated above there is no read user/password support in Android and we don't want to use any hardcoded passwords (that's the reason why we run dropbear with the option -s (no-password).
To generate a key-pair we do:
dropbearkey -t rsa -f /sdcard/id_rsa dropbearkey -f /sdcard/id_rsa -y > /sdcard/id_rsa.pub
This first command generates a private key, the second step extracts the public-key.
Now we jst need to create /data/dropbear/.ssh and cat the public-key to authorized_keys:
mkdir /data/dropbear/.ssh cat /sdcard/id_rsa.pub > /data/dropbear/.ssh/authorized_keys
now check the perms of /data/dropbear/.ssh and /data/dropbear/.ssh/authorized_keys and make sure they are only readable/writable by root.
Now it's time to take care of the client. As dropbear and openssh use different key formats we first need to convert id_rsa (private key) to openssh-format:
/sdcard/dropbearconvert dropbear openssh /sdcard/id_rsa /sdcard/id_rsa_openssh
Now move /sdcard/id_rsa and /sdcard/id_rsa_openssh to your desktop (e.g. to your home). We move them instead of copying them as leaving a private key on the phone may compromise it.
Finally connect to the phone:
ssh -i id_rsa_openssh <phone-ip>
If the connection fails check the Troubleshooting section.
That's it!
As stated before both the client and the server are quite sensitive to the sensitive files having the right perms. You can use -vv for both the client and the server to see debug info and fix whatever is wrong.
Common errors are:
.ssh, authorized_keys or your private key have wrong permsauthorized_keys/etc/shells file with the path to your shell (e.g. /system/bin/sh) will prevent dropbear from opening a session
Discussion
I followed your instruction and still cannot launch dropbear. The error indication "not found". I have check my exe permission and path and all seems to be okay. Any suggestion?
I have busybox installed at /bin and /etc/shells pointing to /system/bin/sh
Thanks,
Alvin
# env
ANDROID_ROOT=/system
PWD=/system
LD_LIBRARY_PATH=/system/lib
PATH=/bin:/sbin:/system/sbin:/system/bin:/system/xbin
BOOTCLASSPATH=/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
ANDROID_BOOTLOGO=1
ANDROID_ASSETS=/system/app
EXTERNAL_STORAGE=/sdcard
ANDROID_DATA=/data
ANDROID_PROPERTY_WORKSPACE=9,32768
# which dropbear
/system/xbin/dropbear
# which dropbearkey
/system/xbin/dropbearkey
# dropbear
dropbear: not found
# dropbearkey
dropbearkey: not found
more info at
http://stackoverflow.com/questions/1043257/installing-a-prebuilt-binary-on-android-not-found
Alvin
Gnu/Linux sid, sourcery toolchain. Upatched code compiles fine.
====================
sshpty.c:45: error: conflicting types for 'openpty'
/home/jeff/gnuarm/bin/../arm-none-linux-gnueabi/libc/usr/include/pty.h:34: note: previous declaration of 'openpty' was here
sshpty.c: In function 'openpty':
sshpty.c:57: warning: implicit declaration of function 'grantpt'
sshpty.c:60: warning: implicit declaration of function 'unlockpt'
sshpty.c:63: warning: implicit declaration of function 'ptsname'
sshpty.c:63: warning: assignment makes pointer from integer without a cast
make: *** [sshpty.o] Error 1