CentOS 7.2 编译安装dropbear

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 编译安装dropbear前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Dropbear是一个相对较小的SSH服务器和客户端。是另一款ssh协议的开源实现;


主要功能

类似于OpenSSH,实现完整的SSH客户端和服务器版本2协议。但它不支持SSH版本1,以节省空间和资源,并避免在SSH版本1的固有的安全漏洞。支持scp。


安装环境:

1、CentOS 7.2:

  1. [root@CentOS7~]#cat/etc/redhat-release
  2. CentOSLinuxrelease7.2.1511(Core)

2、安装开发环境,提供编译环境:

  1. [root@CentOS7~]#yumgroupinstall"DevelopmentTools""ServerPlateformDevelopment"-y

3、安装zlib依赖包文件,不然后续编译会报错:

  1. [root@CentOS7~]#yum-yinstallzlib-devel


编译安装及配置:

1、下载dropbear:

  1. [root@CentOS7src]#wgethttp://matt.ucc.asn.au/dropbear/dropbear-2016.74.tar.bz2
  2. --2016-11-0816:56:44--http://matt.ucc.asn.au/dropbear/dropbear-2016.74.tar.bz2
  3. 正在解析主机matt.ucc.asn.au(matt.ucc.asn.au)...130.95.13.18,2405:3c00:5200:100::18
  4. 正在连接matt.ucc.asn.au(matt.ucc.asn.au)|130.95.13.18|:80...已连接。
  5. 已发出HTTP请求,正在等待回应...200OK
  6. 长度:1622234(1.5M)[application/x-bzip2]
  7. 正在保存至:“dropbear-2016.74.tar.bz2
  8. 100%[======================================>]1,622,234539KB/s用时2.9s
  9. 2016-11-0816:56:50(539KB/s)-已保存“dropbear-2016.74.tar.bz2”[1622234/1622234])


2、解压dropbear-2016.74.tar.bz2

  1. [root@CentOS7src]#tarxfdropbear-2016.74.tar.bz2


3、编译/安装dropbear:

1)运行configure脚本:

  1. [root@CentOS7dropbear-2016.74]#./configureprefix=/usr/local/dropbear--sysconfdir=/etc/dropbear--disable-pam
  2. 显示如下信息表示./configure运行成功,提示编辑options.sh文件选择功能,在此文件中可以设置监听的端口号:
  3. configure:Noweditoptions.htochoosefeatures.

2)运行make命令,完成项目构件:

  1. [root@CentOS7dropbear-2016.74]#makePROGRAMS="dropbeardbclientdropbearkeydropbearconvertscp"

3)运行make install命令,完成安装:

  1. [root@CentOS7dropbear-2016.74]#makePROGRAMS="dropbeardbclientdropbearkeydropbearconvertscp"install
  2. Dropbearkey是用来生成公钥的;
  3. Dropbearconvert是用来与openssh转换的;
  4. Dbclient可以用来连接远程的服务器;
  5. 用法:#./dbclientusername@192.168.99.214
  6. Scp可以向远程的服务器写文件和取文件
  7. 用法:#./scp/home/bin/a.logusername@192.168.99.214:/home/working


4、配置系统环境变量:

  1. [root@CentOS7~]#vim/etc/profile.d/dropbear.sh
  2. [root@CentOS7~]#cat/etc/profile.d/dropbear.sh
  3. exportPATH=/usr/local/dropbear/bin:/usr/local/dropbear/sbin/:$PATH
  4. [root@CentOS7~]#./etc/profile.d/dropbear.sh


5、配置dropbear服务器端:

  1. #dropbear-h
  2. -rkeyfileSpecifyhostkeys(repeatable)
  3. defaults:
  4. dss/etc/dropbear/dropbear_dss_host_key
  5. rsa/etc/dropbear/dropbear_rsa_host_key
  6. ecdsa/etc/dropbear/dropbear_ecdsa_host_key
  7. -RCreatehostkeysasrequired
  8. -FDon'tforkintobackground
  9. -ELogtostderrratherthansyslog


(1)sshd服务器都需要公钥,生成公钥:

  1. #mkdir/etc/dropbear
  2. #cd/etc/dropbear
  3. #dropbearkey-tdss-fdropbear_dss_host_key//生成dss密钥文件
  4. #dropbearkey-trsa-s2048-fdropbear_rsa_host_key//生成rsa密钥文件

(2)启动dropbear:

启动dropbear命令进程时注意监听的端口号:

方法1:使用-p选项指定监听的端口:

  1. [root@CentOS7~]#dropbear-p2022

方法2:在编译dropbear之前,修改options.sh文件

  1. defineDROPBEAR_DEFPORT"22"改为defineDROPBEAR_DEFPORT"2022"
  2. 或执行:#sed-i's/22/2022/g'options.h

启动dropbear:

  1. [root@CentOS7~]#dropbear-p2022

查看端口是否监听成功:

  1. [root@CentOS7~]#ss-tnlp|grep:2022
  2. LISTEN0128*:2022*:*users:(("dropbear",pid=27687,fd=4))
  3. LISTEN0128:::2022:::*users:(("dropbear",fd=5))


6、设置firwalld开放2022端口:

  1. [root@CentOS7~]#firewall-cmd--add-port=2022/tcp--permanent
  2. success
  3. [root@CentOS7~]#firewall-cmd--reload
  4. success
  5. [root@CentOS7~]#firewall-cmd--list-all
  6. public(default,active)
  7. interfaces:enp0s3enp0s8
  8. sources:
  9. services:dhcpv6-clienthttpssh
  10. ports:53/tcp53/udp2022/tcp
  11. masquerade:no
  12. forward-ports:
  13. icmp-blocks:
  14. richrules:


7、使用ssh client端测试:

  1. #ssh-p2022root@172.16.100.11


8、设置为服务:

以下脚本内容来自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=29584738&id=4234090


  1. #vim/etc/rc.d/init.d/dropbear
  2. #!/bin/bash
  3. #
  4. #description:dropbeaRSShdaemon
  5. #chkconfig:23456633
  6. #
  7. dsskey=/etc/dropbear/dropbear_dss_host_key
  8. rsakey=/etc/dropbear/dropbear_rsa_host_key
  9. lockfile=/var/lock/subsys/dropbear
  10. pidfile=/var/run/dropbear.pid
  11. dropbear=/usr/local/sbin/dropbear
  12. dropbearkey=/usr/local/bin/dropbearkey
  13. [-r/etc/rc.d/init.d/functions]&&./etc/rc.d/init.d/functions
  14. [-r/etc/sysconfig/dropbear]&&./etc/sysconfig/dropbear
  15. keysize=${keysize:-1024}
  16. port=${port:-22}
  17. gendsskey(){
  18. [-d/etc/dropbear]||mkdir/etc/dropbear
  19. echo-n"Startinggeneratethedsskey:"
  20. $dropbearkey-tdss-f$dsskey&>/dev/null
  21. RETVAL=$?
  22. if[$RETVAL-eq0];then
  23. success
  24. echo
  25. return0
  26. else
  27. failure
  28. echo
  29. return1
  30. fi
  31. }
  32. genrsakey(){
  33. [-d/etc/dropbear]||mkdir/etc/dropbear
  34. echo-n"Startinggeneratethersakey:"
  35. $dropbearkey-trsa-s$keysize-f$rsakey&>/dev/null
  36. RETVAL=$?
  37. if[$RETVAL-eq0];then
  38. success
  39. echo
  40. return0
  41. else
  42. failure
  43. echo
  44. return1
  45. fi
  46. }
  47. start(){
  48. [-e$dsskey]||gendsskey
  49. [-e$rsakey]||genrsakey
  50. if[-e$lockfile];then
  51. echo-n"dropbeardaemonisalreadyrunning:"
  52. success
  53. echo
  54. exit0
  55. fi
  56. echo-n"Startingdropbear:"
  57. daemon--pidfile="$pidfile"$dropbear-p$port-d$dsskey-r$rsakey
  58. RETVAL=$?
  59. echo
  60. if[$RETVAL-eq0];then
  61. touch$lockfile
  62. return0
  63. else
  64. rm-f$lockfile$pidfile
  65. return1
  66. fi
  67. }
  68. stop(){
  69. if[!-e$lockfile];then
  70. echo-n"dropbearserviceisstopped:"
  71. success
  72. echo
  73. exit1
  74. fi
  75. echo-n"Stoppingdropbeardaemon:"
  76. killprocdropbear
  77. RETVAL=$?
  78. echo
  79.  
  80. if[$RETVAL-eq0];then
  81. rm-f$lockfile$pidfile
  82. return0
  83. else
  84. return1
  85. fi
  86. }
  87. status(){
  88. if[-e$lockfile];then
  89. echo"dropbearisrunning..."
  90. else
  91. echo"dropbearisstopped..."
  92. fi
  93. }
  94. usage(){
  95. echo"Usage:dropbear{start|stop|restart|status|gendsskey|genrsakey}"
  96. }
  97. case$1in
  98. start)
  99. start;;
  100. stop)
  101. stop;;
  102. restart)
  103. stop
  104. start
  105. ;;
  106. status)
  107. status
  108. ;;
  109. gendsskey)
  110. gendsskey
  111. ;;
  112. genrsakey)
  113. genrsakey
  114. ;;
  115. *)
  116. usage
  117. ;;
  118. esac


ps:编译时报错:

  1. configure:error:***zlibmissing-installfirstorcheckconfig.log***

猜测因为安装的版本过新,需升级zlib:

http://www.aixchina.net/Article/39407


安装编译完最新的zlib之后,发现还是不行,搜索之,又发现一篇好文,解决了:

http://blog.csdn.net/shunzi19860518/article/details/479682

猜你在找的CentOS相关文章