dropbear编译及研究

本文介绍dropbear的编译和使用。

一、准备工作

下载dropbear源码。地址:

1
https://matt.ucc.asn.au/dropbear/dropbear.html

下载的文件为dropbear-2018.76.tar.bz2

下载zlib,地址:

1
http://www.zlib.net/

下载文件名为zlib-1.2.11.tar.gz

二、编译zlib

1
2
tar zxf zlib-1.2.11.tar.gz 
./configure --prefix=/home/latelee/bin/zlib-arm --static

修改得到的Makefile文件,将CC改为交叉编译器:

1
CC=arm-linux-gcc

编译安装:

1
2
make -j
make install

三、编译dropbear

1
2
3
4
5
tar jxf dropbear-2018.76.tar.bz2 

./configure --prefix=/home/latelee/bin/dropbear-arm --with-zlib=/home/latelee/bin/zlib-arm/ --host=arm-linux
make -j
make install

最终得到的文件在/home/latelee/bin/dropbear-arm目录下。其中sbin子目录为dropbear服务端,bin子目录为客户端。

四、使用dropbear

将dropbear-arm目录拷贝到板子上(通过U盘可SD卡或ftp方式)。执行如下命令:

1
2
3
4
mkdir /etc/dropbear
cd /etc/dropbear/
dropbearkey -t rsa -f dropbear_rsa_host_key
dropbearkey -t dss -f dropbear_dss_host_key

运行dropbear:

1
dropbear &

默认使用22端口。可以在/etc/rc.d/rc.local文件最后添加该命令,达到开机自动运行的目的。

五、排错

提示:

1
2
3
4
$ dropbearkey -t dss -f dropbear_dss_host_key 
Generating 1024 bit dss key, this may take a while...
dropbearkey: ../sysdeps/unix/sysv/linux/getpagesize.c:32: __getpagesize: Assertion `_rtld_global_ro._dl_pagesize != 0' failed.
Aborted

解决:在configure时将--enable-static去掉,即不使用静态链接的方法。

提示:

1
2
$ dropbearkey -t rsa -f dropbear_rsa_host_key
Exited: Faylure reading ra~dom devyce /dev/urqndom

解决:

1
ln -s /dev/urandom /dev/urqndom

客户端连接提示:

1
ssh_dispatch_run_fatal: Connection to 172.18.18.10 port 22: Connection timed out

原因:没有网络或网络不好。

六、备注

1
2
3
4
5
6
7
8
9
10
11
$ dropbearkey -t rsa -f dropbear_rsa_host_key
Generating 2048 bit rsa key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCroNaSm4Kft7774HOdDdh/tspekJJkuEByLsEg6gYd2t8YiCiLhPqp/cm0TAYwok+IS7Nj78BER01jUsPQkRWW0Zs/Wlio77wm644y3CxVlgEGrUj2FxKoqRkhuEXSYmdSsYeeaxfUhURAwpCtRzrH9fkB+P5daGOEFN7vD42fTTK8Odh1I5QPCLCqkiIZ9rzUtrh8s/9ev7DCjTZ5WDjd1u7N4iN7p0qoY1tKWObh4qawRAMos+VtiawOY1idbjVk8wWLgfAVgaaG5f7HJ5b4sdkBH6RgMh2dcdK6vCMhi5vJ5y1MB4HmhQCG4AGlq7/C8+hzFzVag8ho9qB2vx8z root@freescale
Fingerprint: sha1!! 57:d8:9b:e5:48:55:5b:a2:7c:83:7d:a1:47:27:99:c4:5b:1b:70:c8

$ dropbearkey -t dss -f dropbear_dss_host_key
Generating 1024 bit dss key, this may take a while...
Public key portion is:
ssh-dss AAAAB3NzaC1kc3MAAACBAIzIU44OlJ6nrMgxRxE+Okc7IWnT2duY2QOXmSaWmi+kRU6Mry7AI8l9wO6i6Of44Fs8dEKRbkd+5QQ7nj6MPQAVGIHysepEaFh/MnbEIAu+qmmwMnoVdIW+6WvZ3YEyCdaJL44c1XkkV9ZTJpvXzrsKBqayW+00AnBYf8aVPINxAAAAFQCwbDET1l4zP3d+Fvqq48uA2L94GwAAAIAl0e2OmkWYcus2GvPFqud771OAEl2LI7du6/EnkXAmgkdT+jtUjkBxJR83tnqH41vuEjxo9HtIN0YfxBBjI5y/WzQgzLsch9SBNhpkwKYidTOKHOBCIgfQtqmcIpOTaMFLUnmnt83mCZMp9kldupd9gCf2XIWumImlqz80ZX+xcQAAAIAdF49XrW/+vnCr0LPm5vrMrOB0X8IXv8NmNv+fiH5KEfMZUCKD53iGVH0JQTIbVSetBlFg8LZzJ9ItjQAICt0iEwdw7PnH48fLotgSjqHOj0EbF4GZ8snK3mNWaz7pS5wTKbQsNgljmqCn2TWEjkrNUNGA55eXOOIsgFEBCxD/OQ== root@freescale
Fingerprint: sha1!! d2:4b:7d:c5:ff:ac:24:33:30:28:72:a2:ca:d9:ef:30:df:23:a0:7f