Dropbear 是一套来自澳大利亚的 *nix SSH 工具集,以体积微小著称,因此在嵌入式环境被广泛中使用。
1. 编译 dropbear
$ wget %7Ematt/dropbear/releases/dropbear-0.52.tar.gz
$ wget
$ tar zxvf dropbear-0.52.tar.gz
$ cd dropbear-0.52
$ patch -p1 < ../dropbear0.52-android.patch
patching file common-session.c
patching file loginrec.c
patching file runopts.h
patching file svr-auth.c
patching file svr-authpasswd.c
patching file svr-authpubkey.c
patching file svr-chansession.c
patching file svr-runopts.c
1) zlib support
所使用的编译器未有zlib库支持,因此需要先未其增加zlib支持,/home/install为交叉编译器所在目录。
$ ls -l /home/install
lrwxrwxrwx 1 root root 54 2009-11-28 10:50 /home/install -> /home/goosen/works/buildroot/build_arm/staging_dir/usr
$ ./configure --prefix=/home/install
$ make CC=arm-linux-gcc
$ make install
2) 静态编译 dropbear
$ cd dropbear-0.52/
$ ./configure --host=arm-linux
//$ STATIC=1 make PROGRAMS="dropbear dropbearkey"
$ STATIC=1 make
2. 配置 dropbear
1) generate keys
~ $: adb shell
# mkdir /data/dropbear
# dropbearkey -t rsa -f /data/dropbear/dropbear_rsa_host_key
# dropbearkey -t dss -f /data/dropbear/dropbear_dss_host_key
2) start dropbear
# dropbear -h
Dropbear sshd v0.52
Usage: dropbear [options]
Options are:
-A Android Mode, specify a user explicitly
-N Android Mode, user name
-C Android Mode, password
-R Android Mode, public key file (authorized_keys)
-U Android Mode, UID
-G Android Mode, GID
-b bannerfile Display the contents of bannerfile before user login
(default: none)
-d dsskeyfile Use dsskeyfile for the dss host key
(default: /etc/dropbear/dropbear_dss_host_key)
-r rsakeyfile Use rsakeyfile for the rsa host key
(default: /etc/dropbear/dropbear_rsa_host_key)
-F Don't fork into background
-E Log to stderr rather than syslog
-m Don't display the motd on login
-w Disallow root logins
-s Disable password logins
-g Disable password logins for root
-j Disable local port forwarding
-k Disable remote port forwarding
-a Allow connections to forwarded ports from any host
-p [address:]port
Listen on specified tcp port (and optionally address),
up to 10 can be specified
(default port is 22 if none specified)
-P PidFile Create pid file PidFile
(default /var/run/dropbear.pid)
-i Start for inetd
-W (default 24576, larger may be faster, max 1MB)
-K (0 is never, default 0)
-I (0 is never, default 0)
# ln -s /data/dropbear /etc/dropbear
# dropbear -E
让android启动的时候自动启动 dropbear, 编辑 /init.rc,增加,
#dropbear start
service dropbear /system/sbin/dropbear -E
oneshot
3) connect (u can use dyndns from market to get a domain name )
$ ssh root@yourdomain.dyndns.org
# cat /home/root/.profile
PATH=/usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/data/local/bin
export PATH
# ps | grep 'dropbear'
797 root 436 S /system/sbin/dropbear -E
973 root 492 S /system/sbin/dropbear -E
984 root 492 S /system/sbin/dropbear -E
1036 root 3044 S grep dropbear
注,此处是~/.profile文件(默认环境变量),而不是~/.bashrc。不过/data/dropbear/.profile 未起作用,暂时不明。
3. 碰到的问题及解决方法
1)为用户设置密码出现,
# passwd root
passwd: unknown uid 0
修改 /etc/passwd 如下,
/ # cat /etc/passwd
#root:x:1000:1000:Linux User,,,:/home/root:/bin/sh
root:x:0:0:Linux User,,,:/home/root:/bin/sh
2)登录的时候dropbear提示,
user 'root' has invalid shel
确保/etc/passwd与/etc/shells中shell的设置一致,
# cat /etc/shells
#/system/bin/sh
/bin/sh
源码、补丁及参考的相关文档如下,
http://blog.csdn.net/tekkamanitachi/archive/2009/06/26/4300854.aspx
~matt/dropbear/releases/dropbear-0.52.tar.gz
http://blog.linjian.org/articles/dropbear-pam-patch/
阅读(2336) | 评论(0) | 转发(0) |