700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 使用autossh实现开机创建ssh tunnel的方法以及shell脚本.

使用autossh实现开机创建ssh tunnel的方法以及shell脚本.

时间:2022-01-05 13:56:50

相关推荐

使用autossh实现开机创建ssh tunnel的方法以及shell脚本.

有时候回需要到ssh tunnel,手动使用ssh 创建这些并没有太大的问题,可是如果尝试开机启动,写个shell脚本并在rc.local里面运行这个脚本并不成功,原因也不得而知。

后来发现了autossh这东东,不单单能够静默模式创建ssh tunnel还能设置自动检测,并自动尝试链接的选项。

本文附件提供的脚本,需要放置在/etc/ini.d/目录下,并使用chmod +x 修改权限。然后也有必要使用update-rc.d service defaults添加入开机启动服务。

当然不要忘记修改脚本中的配置信息。

然后就能够在开机时候自动创建ssh tunnel了。 enjoy it.

#!/bin/bash#Foreachtunnel;makeauniquelynamedcopyofthistemplate.##SETTINGS##autosshmonitoringport(unique)MPORT=54321#thesshtunneltosetupTUNNEL="-L:localhost:"#remoteuserRUSER="socieer"#remoteserverRSERVER="socieer.axxeo.de"#Youmustusetherealautosshbinary,notawrapper.DAEMON=/usr/lib/autossh/autossh###ENDSETTINGSPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binNAME=`basename$0`PIDFILE=/var/run/${NAME}.pidSCRIPTNAME=/etc/init.d/${NAME}DESC="thetunnel"test-x$DAEMON||exit0exportAUTOSSH_PORT=${MPORT}exportAUTOSSH_PIDFILE=${PIDFILE}ASOPT=${TUNNEL}"-f-N"${RUSER}"@"${RSERVER}#Functionthatstartsthedaemon/service.d_start(){start-stop-daemon--start--quiet--pidfile$PIDFILE\--exec$DAEMON--$ASOPTif[$?-gt0];thenecho-n"notstarted(oralreadyrunning)"elsesleep1start-stop-daemon--stop--quiet--pidfile$PIDFILE\--test--exec$DAEMON>/dev/null||echo-n"notstarted"fi}#Functionthatstopsthedaemon/service.d_stop(){start-stop-daemon--stop--quiet--pidfile$PIDFILE\--exec$DAEMON\||echo-n"notrunning"}case"$1"instart)echo-n"Starting$DESC:$NAME"d_startecho".";;stop)echo-n"Stopping$DESC:$NAME"d_stopecho".";;restart)echo-n"Restarting$DESC:$NAME"d_stopsleep1d_startecho".";;*)echo"Usage:$SCRIPTNAME{start|stop|restart}">&2exit3;;esacexit0

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。