Cross-compile dropbear/dbclient ssh for arm/Android

Get the latest source code at https://matt.ucc.asn.au/dropbear/dropbear.html


Settings compilers
export API_LEVEL=android-23  # Android 6.0
export COMPILER_ARCH=arm-linux-androideabi-4.9
export ANDROID_NDK=/home/usrname/adr/ndk # or your Android NDK root directory
export CC=${ANDROID_NDK}/toolchains/$COMPILER_ARCH/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
export CCOPT="-O2 -fpic --sysroot=/home/ducalpha/adr/ndk/platforms/$API_LEVEL/arch-arm -DANDROID -DOS_ANDROID -pie"
export CFLAGS="--sysroot=${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm -DANDROID -DOS_ANDROID"
export LDFLAGS="--sysroot=${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm -fPIC -mandroid -L${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm/usr/lib -pie" # add -pie (position independent executable) for running on multiple phones


Configure and make
cd dropbear-2016.73/  # enter source code directory
./configure --host=arm-linux  --disable-utmp --disable-wtmp --disable-utmpx --disable-zlib --disable-syslog # need to disable utmp because ndk does not support it well (e.g., DEAD_PROCESS undeclared)
make

Known limitations
The compiled dbclient seems not support the password authentication but only the public/private key pair

Generate private/public key pair
export HOME=/data/local/tmp/my_home
./dropbearkey -t rsa -s 2048 -f $HOME/.ssh/id_dropbear # generate 2048-bit RSA private key
./dropbearkey -y -f $HOME/.ssh/id_dropbear | grep "^ssh-rsa" > dropbear_key.pub
Use dbclient
./dbclient -y -i dropbear_key_pair username@host.com #-y means no check the target host signature, -i means using the key pair

Useful shortcut
Write script /system/bin/ssh with the following content so that you can invoke ssh anywhere
#!/system/bin/sh
export HOME=/data/local/tmp/my_home  # some custom path
/system/bin/dbclient -i /data/local/.ssh/id_dropbear $*










Comments

Popular posts from this blog

Cross compile libpcap for Android/arm

cross compile git for arm/Android