一:实验目的:
编译安装新版本的dropbear
二:实验过程:
1、dropbear:是一个小型的ssh服务器和客户端,所以和openssh类似,都是用于实现ssh安全远程登录协议的,系统默认安装有openssh,而dropbear是基于epel源的,需要自己下载安装,两种选择一种实现ssh即可,因为两者默认使用22端口,但若是你很想两个都用,那么就可以让其中一个不走默认端口。
2、使用yum info dropbear可查看其信息,(前提是,你需要配好epel源)
[root@localhost ~]# yum info dropbear
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
Name : dropbear
Arch : x86_64
Version : 2016.74 #版本信息
Release : 1.el7
Size : 146 k
Repo : epel
Summary : Lightweight SSH server and client
URL : #官网
License : MIT
Description : Dropbear is a relatively small SSH server and client. It's
: particularly useful for "embedded"-type Linux (or other Unix)
: systems, such as wireless routers.
[root@localhost ~]#
现在我的版本是2016.74版,所以我们可以根据提供的官网,去找一个最新版本的dropbear;如下图所示,点击dropbear-2017.75.tar.bz2,下载。
然后将其放在桌面上(方便上传linix),如下面所示,将dropbear-2017.75.tar.bz2拷进linux的家目录下了(rz是默认拷到当前目录下的)
[root@localhost ~]# rz #执行rz命令,将dropbear-2017.75.tar.bz2拷进来
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring dropbear-2017.75.tar.bz2...
100% 1585 KB 1585 KB/sec 00:00:01 0 Errors
[root@localhost ~]# ls
anaconda-ks.cfg Downloads initial-setup-ks.cfg Public
bin dropbear-2017.75.tar.bz2 ip.log Templates
Desktop httpd-2.4.27 Music Videos
Documents httpd-2.4.27.tar.bz2 Pictures
[root@localhost ~]#
执行tar xvf dropbear-2017.75.tar.bz2将其解压缩,生成dropbear-2017.75 的目录文件,
[root@localhost ~]# tar xvf dropbear-2017.75.tar.bz2
[root@localhost ~]# cd dropbear-2017.75/ #进到目录下
看一下,README(关于dropbear的介绍)和INSTALL(编译的指南)文件;(下面是INSTALL文件)
[root@localhost ~/dropbear-2017.75]# cat INSTALL
Basic Dropbear build instructions:
- Edit options.h to set which features you want.
- Edit debug.h if you want any debug options (not usually required).
(If using a non-tarball copy, "autoconf; autoheader")
./configure (optionally with --disable-zlib or --disable-syslog, #第一步
or --help for other options)
Now compile:
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" #第二步
And install (/usr/local/bin is usual default):
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install #第三步
3、编译过程:
3.1)、首先,检查一下"development tools"这个包组是否安装,若没有装可以先装上,也可以在编译过程中,报错时再安装,这里我先安装一下:
[root@localhost ~]# yum groupinstall "development tools" #大小写都可以
3.2)、然后:如下所示开始编译,其中--prefix=/app/dropbear指定安装后的总目录位置,--sysconfdir=/etc/dropbear/是指定其配置文件存放路径
[root@localhost ~/dropbear-2017.75]# ./configure --prefix=/app/dropbear --sysconfdir=/etc/dropbear/
执行第一次结果报错:
configure: error: *** zlib missing - install first or check config.log ***
然后我们就根据报错信息加上-devel去查找并且安装:
[root@localhost ~/dropbear-2017.75]# yum search zlib-devel #查看一下是否有这个包
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
============================================== N/S matched: zlib-devel ===============================================
ghc-zlib-devel.x86_64 : Haskell zlib library development files
zlib-devel.i686 : Header files and libraries for Zlib development
zlib-devel.x86_64 : Header files and libraries for Zlib development
Name and summary matches only, use "search all" for everything.
[root@localhost ~/dropbear-2017.75]# yum -y install zlib-devel #加上-y选项直接安装
3.3)、将第一个错误排除后,再执行一次编译,若还有错,就根据提示加上-devel查找,安装,直到编译最后如下图代码所示,成功(上面的代码省略,只截取的最后);注意:若在这一步频繁出错,而且在开始没有安装"development tools"这个包组的话,建议先装一下这个包组,过程就会顺利多了。
checking for writev... yes
checking for library containing basename... none required
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libtomcrypt/Makefile
config.status: creating libtommath/Makefile
config.status: creating config.h
configure:
configure: Using bundled libtomcrypt and libtommath
configure:
configure: Now edit options.h to choose features.
[root@localhost ~/dropbear-2017.75]#
3.4)、根据INSTALL文件的提示,进行第二步make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"(只写make也行,但是这里我按照提示做的),在这个过程按道理说不会再出错的,(若有错的话在configer那一步应该就会报错),而且在这个过程中会出现一些warning信息,可以不用管(哈哈,因为它不是erro *-*),最后代码如下图所示
scpmisc.c: In function ‘freeargs’:
scpmisc.c:196:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < args->num; i++)
^
gcc -o scp scp.o progressmeter.o atomicio.o scpmisc.o compat.o
3.5)、第三步:在第二步的代码后加上instll即可,make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install;可以看到下载的文件,在/app/dropbear下。
其中:bin下的是客户端程序;sbin下的是服务端程序;/app/dropbear/bin/dbclient就相当于ssh协议。
[root@localhost ~/dropbear-2017.75]# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
install -d /app/dropbear/sbin
install dropbear /app/dropbear/sbin #服务端程序
install -d /app/dropbear/share/man/man8
install -m 644 ./dropbear.8 /app/dropbear/share/man/man8/dropbear.8
install -d /app/dropbear/bin
install dbclient /app/dropbear/bin
install -d /app/dropbear/share/man/man1
if test -e dbclient.1; then install -m 644 dbclient.1 /app/dropbear/share/man/man1/dbclient.1; fi
install -d /app/dropbear/bin
install dropbearkey /app/dropbear/bin
install -d /app/dropbear/share/man/man1
if test -e dropbearkey.1; then install -m 644 dropbearkey.1 /app/dropbear/share/man/man1/dropbearkey.1; fi
install -d /app/dropbear/bin
install dropbearconvert /app/dropbear/bin
install -d /app/dropbear/share/man/man1
if test -e dropbearconvert.1; then install -m 644 dropbearconvert.1 /app/dropbear/share/man/man1/dropbearconvert.1; fi
install -d /app/dropbear/bin
install scp /app/dropbear/bin
install -d /app/dropbear/share/man/man1
if test -e scp.1; then install -m 644 scp.1 /app/dropbear/share/man/man1/scp.1; fi
[root@localhost ~/dropbear-2017.75]#
三:实现:
编译安装结束,验证一下:
1、先在/etc/profile.d/下建一个path.sh的文件,定义PATH变量,将我们刚编译安装的目录/app/bin和/app/sbin都添加到PATH里,方便运行(也可以不写,到运行时写绝对路径也行)
[root@localhost ~/dropbear-2017.75]# vim /etc/profile.d/path.sh
export PATH=/app/dropbear/bin:/app/dropbear/sbin:$PATH
[root@localhost ~/dropbear-2017.75]# . /etc/profile.d/path.sh #使其生效
[root@localhost ~/dropbear-2017.75]# echo $PATH #查看PATH变量
/app/dropbear/bin:/app/dropbear/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~/dropbear-2017.75]#
现在发现一个问题:在下载过程中,并没有将我们指定的/etc/dropbear生成,而且我们服务端运行的话需要KEY,所以我们要先生成key(可根据REDME文档中的提示):
[root@localhost ~/dropbear-2017.75]# cat README #截取其中一段
......
To run the server, you need to server keys, this is one-off: #有三种加密方式,任选其一
./dropbearkey -t rsa -f dropbear_rsa_host_key
./dropbearkey -t dss -f dropbear_dss_host_key
./dropbearkey -t ecdsa -f dropbear_ecdsa_host_key
这里我选择用的rsa加密,即第一条,因为前面我们配置过PATH变量了,所以可以直接使用命令,若没配置就需要/app/dropbear/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
[root@localhost /etc/dropbear]# dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCJv8CnwVUc8gjHf1/9PVjKdNFzMUpUZXZXrMVhxJd+91QvpyI6C5cfDEWdc/xfPy0FZ0Wj+Dzg13YhR5R9kEFRb7id1/MUzSVU7JkFTae+zIBzwQ3z+IzQiMcJnlB65zB8d/0aqmibelR1m1VZiNgJtxMco5oSNAZQdv8wgO3bUXrwFR6ZeXg5FeQ9AiLQFCj0ZFvLUQOpRGX4LsQneIZjW9xAZnLpWkYeib+XK7eACpYepBpPetyVirSmImcchf0G5894IK9DYkjnQr+yI9BO6Nw5kXFH9c9QiLoWHeqi5HZXasHiH8+Sq4La8ZEFRxqdFnR4UjckfTJ0fZUUM8DD root@localhost.localdomain
Fingerprint: md5 88:1e:1e:6f:47:a0:da:49:7a:33:a3:39:8e:cb:26:db
[root@localhost /etc/dropbear]# ls
dropbear_rsa_host_key
[root@localhost /etc/dropbear]#
2、现在key也有了,我们就可以考虑启动了,但是我们默认走22端口,但是我们的sshd服务还在开着,所以,我们可以用dropbear --help查一下它的帮助:
[root@localhost /etc/dropbear]# dropbear --help
-F Don't fork into background #放前台执行
-p [address:]port #指定端口号 #指定端口号
Listen on specified tcp port (and optionally address),
up to 10 can be specified
(default port is 22 if none specified)
然后执行命令前先看一下端口信息:
[root@localhost /app/dropbear/bin]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 *:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::23 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 :::25 :::*
执行命令:
[root@localhost /etc/dropbear]# dropbear -F -p 518
再去显示一下端口信息:指定的518端口打开了
[root@localhost /app/dropbear/bin]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 *:25 *:*
LISTEN 0 128 *:518 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::23 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 :::25 :::*
LISTEN 0 128 :::518 :::*
[root@localhost /app/dropbear/bin]#
OK,那我们开始连接:
3、
1)、现在用另外一台主机A(客户端)去连接我们刚安装dropbear服务的机器B(服务器端)(A:192.168.242.202;B:192.168.242.248)
[root@Centos6 ~]# ssh 192.168.242.248 -p 518
The authenticity of host '[192.168.242.248]:518 ([192.168.242.248]:518)' can't be established.
RSA key fingerprint is 88:1e:1e:6f:47:a0:da:49:7a:33:a3:39:8e:cb:26:db.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.242.248]:518' (RSA) to the list of known hosts.
root@192.168.242.248's password:
[root@localhost ~]#
[root@localhost ~]# ss -ntp #可以看到是dropbear连接的518端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.242.248:22 192.168.242.1:51725 users:(("sshd",pid=4681,fd=3))
ESTAB 0 0 192.168.242.248:518 192.168.242.202:54096 users:(("dropbear",pid=15128,fd=6))
[root@localhost ~]#
但注意,因为我们选择的是前台运行,所以,在B机器上我们Ctrl+c后就会断开连接。
2)、也可以用B机器作为客户端,A机器作为服务端
[root@localhost ~]# dbclient 192.168.242.202
root@192.168.242.202's password:
Last login: Sat Sep 30 09:50:26 2017 from 192.168.242.248
[root@Centos6 ~]#
OK,到这里,编译、安装、测试dropbear完成,可能不是特别详细,可能还有些方面没有考虑到,若有不足,请多多指教。*-*
转载于:https://blog.51cto.com/13172997/1969900