Use Autossh to implement the method of creating SSH tunnel on boot and shell script.

Source: Internet
Author: User


Sometimes back to SSH tunnel, the manual use of SSH to create these is not too big a problem, but if you try to boot, write a shell script and run the script in Rc.local is not successful, the reason is not known.

Later discovered autossh this thing, not only can create SSH tunnel silent mode can also set automatic detection, and automatically try to link the options.


The script that is provided in the attachment of this article needs to be placed in the/etc/ini.d/directory and modified with chmod +x permissions. It is then also necessary to use UPDATE-RC.D service defaults to add the boot service to the boot.

Of course, don't forget to modify the configuration information in the script.

You can then automatically create SSH tunnel at boot time. Enjoy it.


#! /bin/bash# for each tunnel; make a uniquely named copy of  this template.## SETTINGS## autossh monitoring port  (unique) mport=54321#  the ssh tunnel to setuptunnel= "-l 2003:localhost:2003" # remote  Userruser= "Socieer" # remote serverrserver= "socieer.axxeo.de" # you must use the  real autossh binary, not a wrapper. daemon=/usr/lib/autossh/autossh### end settingspath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/binname= ' basename $0 ' pidfile=/var/run/${name}.pidscriptname=/etc/init.d/${name}desc= "the  Tunnel "test -x  $DAEMON  | |  exit 0export autossh_port=${mport}export autossh_pidfile=${pidfile}asopt=${tunnel} "  -f -n  "${ruser}" @ "${rserver}#  function that starts the daemon/ Service.d_start ()  { &NBsp; start-stop-daemon --start --quiet --pidfile  $PIDFILE         --exec  $DAEMON  --  $ASOPT    if [ $? -gt 0  ]; then       echo -n  " not started  (or  already running) "   else       sleep 1        start-stop-daemon --stop --quiet --pidfile  $PIDFILE        --test --exec  $DAEMON  > /dev/null | |  echo -n  " not started"    fi}#  Function that  Stops the daemon/service.d_stop ()  {   start-stop-daemon --stop --quiet  --pidfile  $PIDFILE        --exec  $DAEMON         | |  echo -n  " not running"}case  "$"  in  start)    echo  -n  "starting  $DESC:  $NAME"    d_start   echo  "."    ;;   stop)    echo -n  "stopping  $DESC:  $NAME"    d_stop    echo  "."    ;;   restart)    echo -n  "restarting  $DESC:  $NAME"    d _stop   sleep 1   d_start   echo  "."    ;;   *)    echo  "usage:  $SCRIPTNAME  {start|stop|restart}"  >&2    exit 3   ;; Esacexit 0


This article is from the "EIT Tramp" blog, please be sure to keep this source http://zicowarn.blog.51cto.com/3815716/1653604

Use Autossh to implement the method of creating SSH tunnel on boot and shell script.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.