Dropbear是一个相对较小的SSH服务器和客户端。是另一款ssh协议的开源实现;
主要功能:
类似于OpenSSH,实现完整的SSH客户端和服务器版本2协议。但它不支持SSH版本1,以节省空间和资源,并避免在SSH版本1的固有的安全漏洞。支持scp。
安装环境:
1、CentOS 7.2:
- [root@CentOS7~]#cat/etc/redhat-release
- CentOSLinuxrelease7.2.1511(Core)
2、安装开发环境,提供编译环境:
- [root@CentOS7~]#yumgroupinstall"DevelopmentTools""ServerPlateformDevelopment"-y
3、安装zlib依赖包文件,不然后续编译会报错:
- [root@CentOS7~]#yum-yinstallzlib-devel
编译安装及配置:
1、下载dropbear:
- [root@CentOS7src]#wgethttp://matt.ucc.asn.au/dropbear/dropbear-2016.74.tar.bz2
- --2016-11-0816:56:44--http://matt.ucc.asn.au/dropbear/dropbear-2016.74.tar.bz2
- 正在解析主机matt.ucc.asn.au(matt.ucc.asn.au)...130.95.13.18,2405:3c00:5200:100::18
- 正在连接matt.ucc.asn.au(matt.ucc.asn.au)|130.95.13.18|:80...已连接。
- 已发出HTTP请求,正在等待回应...200OK
- 长度:1622234(1.5M)[application/x-bzip2]
- 正在保存至:“dropbear-2016.74.tar.bz2”
- 100%[======================================>]1,622,234539KB/s用时2.9s
- 2016-11-0816:56:50(539KB/s)-已保存“dropbear-2016.74.tar.bz2”[1622234/1622234])
2、解压dropbear-2016.74.tar.bz2
- [root@CentOS7src]#tarxfdropbear-2016.74.tar.bz2
3、编译/安装dropbear:
1)运行configure脚本:
2)运行make命令,完成项目构件:
- [root@CentOS7dropbear-2016.74]#makePROGRAMS="dropbeardbclientdropbearkeydropbearconvertscp"
3)运行make install命令,完成安装:
4、配置系统环境变量:
- [root@CentOS7~]#vim/etc/profile.d/dropbear.sh
- [root@CentOS7~]#cat/etc/profile.d/dropbear.sh
- exportPATH=/usr/local/dropbear/bin:/usr/local/dropbear/sbin/:$PATH
- [root@CentOS7~]#./etc/profile.d/dropbear.sh
5、配置dropbear服务器端:
- #dropbear-h
- -rkeyfileSpecifyhostkeys(repeatable)
- defaults:
- dss/etc/dropbear/dropbear_dss_host_key
- rsa/etc/dropbear/dropbear_rsa_host_key
- ecdsa/etc/dropbear/dropbear_ecdsa_host_key
- -RCreatehostkeysasrequired
- -FDon'tforkintobackground
- -ELogtostderrratherthansyslog
(1)sshd服务器都需要公钥,生成公钥:
(2)启动dropbear:
启动dropbear命令进程时注意监听的端口号:
方法1:使用-p选项指定监听的端口:
- [root@CentOS7~]#dropbear-p2022
方法2:在编译dropbear之前,修改options.sh文件中:
- defineDROPBEAR_DEFPORT"22"改为defineDROPBEAR_DEFPORT"2022"
- 或执行:#sed-i's/22/2022/g'options.h
启动dropbear:
- [root@CentOS7~]#dropbear-p2022
查看端口是否监听成功:
- [root@CentOS7~]#ss-tnlp|grep:2022
- LISTEN0128*:2022*:*users:(("dropbear",pid=27687,fd=4))
- LISTEN0128:::2022:::*users:(("dropbear",fd=5))
6、设置firwalld开放2022端口:
- [root@CentOS7~]#firewall-cmd--add-port=2022/tcp--permanent
- success
- [root@CentOS7~]#firewall-cmd--reload
- success
- [root@CentOS7~]#firewall-cmd--list-all
- public(default,active)
- interfaces:enp0s3enp0s8
- sources:
- services:dhcpv6-clienthttpssh
- ports:53/tcp53/udp2022/tcp
- masquerade:no
- forward-ports:
- icmp-blocks:
- richrules:
7、使用ssh client端测试:
- #ssh-p2022root@172.16.100.11
8、设置为服务:
以下脚本内容来自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=29584738&id=4234090
- #vim/etc/rc.d/init.d/dropbear
- #!/bin/bash
- #
- #description:dropbeaRSShdaemon
- #chkconfig:23456633
- #
- dsskey=/etc/dropbear/dropbear_dss_host_key
- rsakey=/etc/dropbear/dropbear_rsa_host_key
- lockfile=/var/lock/subsys/dropbear
- pidfile=/var/run/dropbear.pid
- dropbear=/usr/local/sbin/dropbear
- dropbearkey=/usr/local/bin/dropbearkey
- [-r/etc/rc.d/init.d/functions]&&./etc/rc.d/init.d/functions
- [-r/etc/sysconfig/dropbear]&&./etc/sysconfig/dropbear
- keysize=${keysize:-1024}
- port=${port:-22}
- gendsskey(){
- [-d/etc/dropbear]||mkdir/etc/dropbear
- echo-n"Startinggeneratethedsskey:"
- $dropbearkey-tdss-f$dsskey&>/dev/null
- RETVAL=$?
- if[$RETVAL-eq0];then
- success
- echo
- return0
- else
- failure
- echo
- return1
- fi
- }
- genrsakey(){
- [-d/etc/dropbear]||mkdir/etc/dropbear
- echo-n"Startinggeneratethersakey:"
- $dropbearkey-trsa-s$keysize-f$rsakey&>/dev/null
- RETVAL=$?
- if[$RETVAL-eq0];then
- success
- echo
- return0
- else
- failure
- echo
- return1
- fi
- }
- start(){
- [-e$dsskey]||gendsskey
- [-e$rsakey]||genrsakey
- if[-e$lockfile];then
- echo-n"dropbeardaemonisalreadyrunning:"
- success
- echo
- exit0
- fi
- echo-n"Startingdropbear:"
- daemon--pidfile="$pidfile"$dropbear-p$port-d$dsskey-r$rsakey
- RETVAL=$?
- echo
- if[$RETVAL-eq0];then
- touch$lockfile
- return0
- else
- rm-f$lockfile$pidfile
- return1
- fi
- }
- stop(){
- if[!-e$lockfile];then
- echo-n"dropbearserviceisstopped:"
- success
- echo
- exit1
- fi
- echo-n"Stoppingdropbeardaemon:"
- killprocdropbear
- RETVAL=$?
- echo
- if[$RETVAL-eq0];then
- rm-f$lockfile$pidfile
- return0
- else
- return1
- fi
- }
- status(){
- if[-e$lockfile];then
- echo"dropbearisrunning..."
- else
- echo"dropbearisstopped..."
- fi
- }
- usage(){
- echo"Usage:dropbear{start|stop|restart|status|gendsskey|genrsakey}"
- }
- case$1in
- start)
- start;;
- stop)
- stop;;
- restart)
- stop
- start
- ;;
- status)
- status
- ;;
- gendsskey)
- gendsskey
- ;;
- genrsakey)
- genrsakey
- ;;
- *)
- usage
- ;;
- esac
ps:编译时报错:
- configure:error:***zlibmissing-installfirstorcheckconfig.log***
猜测因为安装的版本过新,需升级zlib:
http://www.aixchina.net/Article/39407