Use autossh to automatically restart SSH sessions and channels

Source: Internet
Author: User

Autossh is a program used to start and monitor ssh. You can restart ssh when necessary, for example, if the program crashes or the network encounters a problem. It is inspired by rstunnel (Reliable SSH Tunnel ). the autossh 1.2 method has changed: autossh uses ssh to construct an ssh redirect loop (Local to remote and remote to local), then sends test data and returns the result.

Autossh 1.3 adds a new method: You can specify the port of the remote echo service to return the test data sending result. This avoids conflicts between the handshake phase and all remote machine ports. The old loop-of-forwardings method is still available.
Install autossh on Ubuntu

Open the terminal window and run the following command

Sudo apt-get install autossh

Autossh syntax

Autossh [-V] [-M port [: echo_port] [-f] [SSH_OPTIONS]

Start the ssh channel at startup

We can use upstart to start the ssh channel in Ubuntu, just put the following autossh. conf file in the/etc/init directory.

# Autossh startup Script

Description "autossh daemon startup"

Start on net-device-up IFACE = eth0
Stop on runlevel [01S6]

Respawn
Respawn limit 5 60 # respawn max 5 times in 60 seconds

Script
Export AUTOSSH_PIDFILE =/var/run/autossh. pid
Export AUTOSSH_POLL = 60
Export AUTOSSH_FIRST_POLL = 30
Export autossh_1_time = 0
Export AUTOSSH_DEBUG = 1
Autossh-M 0-4-n user @ HOSTNAME-D 7070-o "ServerAliveInterval 60"-o "ServerAliveCountMax 3"-o BatchMode = yes-o StrictHostKeyChecking = no-I SSH_KEY_FILE_PATH
End script

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.