Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Dropbear compilation, installation and service scripting

Shulou Source: shulou.com Published: 2022-06-01 03:17:42 10月05日 Update

Compilation and installation

Download dropbear and extract it

# 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

To compile and install dropbear, specify which programs to install dropbear

# make PROGRAMS= "dropbear dbclient dropbearkey dropbearconvert scp" # make PROGRAMS= "dropbear dbclient dropbearkey dropbearconvert scp" install

There is no / etc/dropbear after the installation, and the / etc/dropbear/dropbear_dss_host_key and / etc/dropbear/dropbear_rsa_host_key files-t specify the type-f to be installed there

# 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

You can now start dropbear

# / usr/local/dropbear/sbin/dropbear-p 2222 # listening on port 2222 # ps aux | the grep dropbear # service has started root 25377 0.0 15300 536? Ss 17:50 0:00 / usr/local/dropbear/sbin/dropbear-p 2222root 25379 0.0 103256 856 pts/2 S+ 17:51 0:00 grep dropbear# netstat-tnlp # 2222 port starts listening to Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 00 127.0.0.1 : 8307 0.0.0.0 LISTEN 2861/vmware-hostd tcp * LISTEN 25377/dropbear tcp 0:: 22:: * LISTEN 2576/sshd tcp 0 0: 2222: * LISTEN 25377/dropbear # ss-tanltate Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100: 2222: * LISTEN 0 100 *: 2222 *: *

Change to another port

Xshell:\ > ssh 192.168.1.9 2222 # can be connected

Do not want to use ssh service, go back to the original port

# chkconfig sshd off # default boot does not start # service sshd stop

The writing of service script

If you want dropbear to boot, switch to port 2222.

# vim / etc/rc.d/rc.local/usr/local/dropbear/sbin/dropbear-p 222boot can be started, but cannot be shut down. Write a service script # vim / etc/sysconfig/dropbear port=2222# vim / ETC _ etc/rc.d/init.d/functions _ init. D _ init. D _ bind _ blank _ init. Chkconfig: 2345 75 50 default level startup level off level # description: lightweight ssh3 implementation# [- r / etc/rc.d/init.d/functions] & &. / etc/rc.d/init.d/functions [- f / etc/sysconfig/dropbear] & &. / etc/sysconfig/dropbeardsskey=/etc/dropbear/dropbear_dss_host_keyrsakey=/etc/dropbear/dropbear_rsa_host_keypidfile=/var/run/dropbear.pidlockfile=/var/lock/subsys/dropbeardropbearkey=/usr/local/dropbear/bin/dropbearkeydropbear=/usr/local/dropbear/sbin/dropbearport=$ {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 # this line does not need RETVAL=$? If [$RETVAL-eq 0]; then echo-n "Generate rsa key finished." Passed echo return 0 else echo-n "Genrate rsakey 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 startStart dropbear [OK] # service dropbear restartStop dropbear: [OK] Start dropbear [OK] # service dropbear stopStop dropbear: [OK]

Tags: Port service level script compile monitor file program type Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn NVidia Shulou Technology Redmi