您好,登錄后才能下訂單哦!
編譯安裝
下載dropbear、并解壓
# wget http://matt.ucc.asn.au/dropbear/releases/dropbear-2015.67.tar.bz2 # tar xvf dropbear-2015.67.tar.bz2 # cd dropbear-2015.67 # ./configure --prefix=/usr/local/dropbear --sysconfdir=/etc/dropbear
編譯安裝dropbear,要指定安裝dropbear的哪些程序
# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" # make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
安裝完成后沒有/etc/dropbear,還要有/etc/dropbear/dropbear_dss_host_key和/etc/dropbear/dropbear_rsa_host_key文件 -t 指定類型 -f 指定安裝到那
# mkdir /etc/dropbear # /usr/local/dropbear/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key # /usr/local/dropbear/bin/dropbearkey -t rsa -s 4096 -f /etc/dropbear/dropbear_rsa_host_key
現在可以啟動dropbear
# /usr/local/dropbear/sbin/dropbear -p 2222 #監聽在2222端口 # ps aux | grep dropbear #服務已經啟動了 root 25377 0.0 0.0 15300 536 ? Ss 17:50 0:00 /usr/local/dropbear/sbin/dropbear -p 2222 root 25379 0.0 0.0 103256 856 pts/2 S+ 17:51 0:00 grep dropbear # netstat -tnlp #2222端口開始監聽 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:8307 0.0.0.0:* LISTEN 2861/vmware-hostd tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN 25377/dropbear tcp 0 0 :::22 :::* LISTEN 2576/sshd tcp 0 0 :::2222 :::* LISTEN 25377/dropbear # ss -tanl tate Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 :::2222 :::* LISTEN 0 100 *:2222 *:*
換一個端口
Xshell :\> ssh 192.168.1.9 2222 #可以連接
不想用ssh服務,回到原端口
# chkconfig sshd off #默認開機不啟動 # service sshd stop
服務腳本的編寫
想讓dropbear開機啟動,換到2222端口
# vim /etc/rc.d/rc.local /usr/local/dropbear/sbin/dropbear -p 2222 #能啟動,但是不能關閉,寫個服務腳本
# vim /etc/sysconfig/dropbear port=2222 # vim /etc/rc.d/init.d/dropbear #!/bin/bash # # chkconfig: 2345 75 50 默認級別 啟動級別 關閉級別 # description: lightweight ssh3 implementation # [ -r /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions [ -f /etc/sysconfig/dropbear ] && . /etc/sysconfig/dropbear dsskey=/etc/dropbear/dropbear_dss_host_key rsakey=/etc/dropbear/dropbear_rsa_host_key pidfile=/var/run/dropbear.pid lockfile=/var/lock/subsys/dropbear dropbearkey=/usr/local/dropbear/bin/dropbearkey dropbear=/usr/local/dropbear/sbin/dropbear port=${port:=22} gendsskey() { if [ ! -f $dsskey ]; then $dropbearkey -t dss -f $dsskey &> /dev/null [ $? -eq 0 ] && return 0 || return 1 RETVAL=$? if [ $RETVAL -eq 0 ]; then echo -n "Generate dss key finished." passed echo return 0 else echo -n "Genrate dss key failed" failure echo exit 6 fi else return 0 fi } genrsakey() { if [ ! -f $rsakey ]; then $dropbearkey -t rsa -f $rsakey -s 2048 &> /dev/null # [ $? -eq 0 ] && return 0 || return 1 #這行不需要了 RETVAL=$? if [ $RETVAL -eq 0 ]; then echo -n "Generate rsa key finished." passed echo return 0 else echo -n "Genrate rsa key failed" failure echo exit 6 fi else return 0 fi } start() { gendsskey genrsakey if [ -f $lockfile ]; then echo -n "dropbear is already running." failure echo exit 7 fi echo -n "Start dropbear" daemon --pidfile $pidfile $dropbear -p $port RETVAL=$? echo if [ $RETVAL -eq 0 ];then touch $lockfile return 0 else rm -f $lockfile $pidfile return 1 fi } stop() { if [ ! -f $lockfile ]; then echo -n "dropbear is not running." failure echo exit 8 fi echo -n "Stop dropbear:" killproc dropbear RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $lockfile && return 0 || return 1 } case $1 in start) start ;; stop) stop;; restart) stop start ;; *) exit 3 ;; esac
# service dropbear start Start dropbear [確定] # service dropbear restart Stop dropbear: [確定] Start dropbear [確定] # service dropbear stop Stop dropbear: [確定]
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。