autossh不生效_autossh 让你的 ssh 不掉线

autossh不生效_autossh 让你的 ssh 不掉线摘要 ssh 是 OPS 及 DEV 同学登录服务器进行维护 部署等的必备工具 我们总会遇到长时间连接 ssh 后会自动断开需要重连的情况 之前我们都是使用 screen 来保证 ssh 不断线 现在有了一个更加给力的工具 autossh autossh 是在 ssh 的基础之上 增加了一个监控端口 防止 sshsession 过期 并可以重新连接保证不掉线 这保证我们在 ssh 执行远程服务器上的运行时间长的脚本时不会

[摘要] ssh是OPS及DEV同学登录服务器进行维护,部署等的必备工具。我们总会遇到长时间连接ssh后会自动断开需要重连的情况,之前我们都是使用screen来保证ssh不断线,现在有了一个更加给力的工具--autossh,autossh 是在ssh的基础之上,增加了一个监控端口,防止ssh session 过期,并可以重新连接保证不掉线,这保证我们在ssh执行远程服务器上的运行时间长的脚本时不会出现意外失联的情况。

下载地址:

download autossh-1.4c.tgz

源码安装,一次编译,到处执行:

gunzip -c autossh-1.4c.tgz | tar xvf –

cd autossh-1.4c

./configure

make

copy binary to where you wish it, or “make install” will install it under /usr/local by default.

examine autossh.host for example wrapper script and options

1

2

3

4

5

6

gunzip-cautossh-1.4c.tgz|tarxvf-

cdautossh-1.4c

./configure

make

copybinarytowhereyouwishit,or”make install”willinstallitunder/usr/localbydefault.

examineautossh.hostforexamplewrapperscriptandoptions

脚本用法

# ./autossh

usage: autossh [-V] [-M monitor_port[:echo_port]] [-f] [SSH_OPTIONS]

-M specifies monitor port. May be overridden by environment

variable AUTOSSH_PORT. 0 turns monitoring loop off.

Alternatively, a port for an echo service on the remote

machine may be specified. (Normally port 7.)

-f run in background (autossh handles this, and does not

pass it to ssh.)

-V print autossh version and exit.

Environment variables are:

AUTOSSH_GATETIME – how long must an ssh session be established

before we decide it really was established

(in seconds). Default is 30 seconds; use of -f

flag sets this to 0.

AUTOSSH_LOGFILE – file to log to (default is to use the syslog

facility)

AUTOSSH_LOGLEVEL – level of log verbosity

AUTOSSH_MAXLIFETIME – set the maximum time to live (seconds)

AUTOSSH_MAXSTART – max times to restart (default is no limit)

AUTOSSH_MESSAGE – message to append to echo string (max 64 bytes)

AUTOSSH_PATH – path to ssh if not default

AUTOSSH_PIDFILE – write pid to this file

AUTOSSH_POLL – how often to check the connection (seconds)

AUTOSSH_FIRST_POLL – time before first connection check (seconds)

AUTOSSH_PORT – port to use for monitor connection

AUTOSSH_DEBUG – turn logging to maximum verbosity and log to

stderr

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

# ./autossh

usage:autossh[-V][-Mmonitor_port[:echo_port]][-f][SSH_OPTIONS]

-Mspecifiesmonitorport.Maybeoverriddenbyenvironment

variableAUTOSSH_PORT.0turnsmonitoringloopoff.

Alternatively,aportforanechoserviceontheremote

machinemaybespecified.(Normallyport7.)

-fruninbackground(autosshhandlesthis,anddoesnot

passittossh.)

-Vprintautosshversionandexit.

Environmentvariablesare:

AUTOSSH_GATETIME-howlongmustansshsessionbeestablished

beforewedecideitreallywasestablished

(inseconds).Defaultis30seconds;useof-f

flagsetsthisto0.

AUTOSSH_LOGFILE-filetologto(defaultistousethesyslog

facility)

AUTOSSH_LOGLEVEL-leveloflogverbosity

AUTOSSH_MAXLIFETIME-setthemaximumtimetolive(seconds)

AUTOSSH_MAXSTART-maxtimestorestart(defaultisnolimit)

AUTOSSH_MESSAGE-messagetoappendtoechostring(max64bytes)

AUTOSSH_PATH-pathtosshifnotdefault

AUTOSSH_PIDFILE-writepidtothisfile

AUTOSSH_POLL-howoftentochecktheconnection(seconds)

AUTOSSH_FIRST_POLL-timebeforefirstconnectioncheck(seconds)

AUTOSSH_PORT-porttouseformonitorconnection

AUTOSSH_DEBUG-turnloggingtomaximumverbosityandlogto

stderr

下面是使用autossh登录服务器的列子:

./autossh -M port remote-ssh-server-IP

如:

./autossh -M 12345 sudops@172.32.5.239

1

2

3

./autossh-Mportremote-ssh-server-IP

如:

./autossh-M12345sudops@172.32.5.239

创建ssh隧道的例子:

autossh -M 12345 -N -D -v localhost:7070 sudops@172.32.5.239 -p 22

会看到如下监听端口:其中7070为本地

tcp 0 0 127.0.0.1:7070 0.0.0.0:* LISTEN 7466/ssh

tcp 0 0 127.0.0.1:12345 0.0.0.0:* LISTEN 7466/ssh

tcp 0 0 127.0.0.1:12346 0.0.0.0:* LISTEN 7465/autossh

1

2

3

4

5

6

autossh-M12345-N-D-vlocalhost:7070sudops@172.32.5.239-p22

会看到如下监听端口:其中7070为本地

tcp00127.0.0.1:70700.0.0.0:*LISTEN7466/ssh

tcp00127.0.0.1:.0.0.0:*LISTEN7466/ssh

tcp00127.0.0.1:.0.0.0:*LISTEN7465/autossh

能够看到autossh启动了一个echo service port 12345作为监控,另外还启动了一个port+1的端口12346作为接收端口,文档描述如下:

When no echo service port is specified, this port and the port

immediately above it (port# + 1) should be something nothing

else is using. autossh will send test data on the base monitoring

port, and receive it back on the port above.

1

2

3

4

Whennoechoserviceportisspecified,thisportandtheport

immediatelyaboveit(port# + 1) should be something nothing

elseisusing.autosshwillsendtestdataonthebasemonitoring

port,andreceiveitbackontheportabove.

怎么样,有意思不,赶快体验下传说中的“高大上” autossh 吧。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/230104.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午3:07
下一篇 2026年3月16日 下午3:07


相关推荐

  • recvfrom error 10022

    recvfrom error 10022http://blog.sina.com.cn/s/blog_6ffee9410100pqdt.html折腾了一个下午加大半个晚上,查了300多个网页,20多个技术论坛,终于把这个问题解决了,真不容易。总结下出现这个错误的一般原因和我出错的原因。出现这个错误的一般原因:1.fromlen参数没有初始化2.from参数没有设置正确,也就是结构问题3.参

    2022年7月23日
    12
  • 主定理求解算法时间复杂度

    主定理求解算法时间复杂度主定理所谓主定理 就是用来解递归方程的一种方法 此方法可以用来求解大多数递归方程 设递归方程为 T n aT n b f n nbsp 其中 a 1 b 1 主定理 nbsp nbsp nbsp 1 如果存在常数 0 有 f n O n logb a 则 T n n logb a nbsp nbsp nbsp 2 若 f n n logb a 则 T n n logb a logn

    2026年3月16日
    2
  • PHP基础

    PHP基础前言发现PHP审计和利用的一些漏洞利用场景挺有意思的,来学习一下php基础内容,大部分概念和代码和Java或c++的差不多,挑些php独有的特性来做记录。基础知识超级全局变量PHP

    2021年12月13日
    43
  • SpringBoot 项目部署到服务器上(Jar包)

    SpringBoot 项目部署到服务器上(Jar包)1.部署方式Springboot和普通web应用程序不一样,其本质上是一个Java应用程序,那么又如何部署呢?通常来说,Springboot部署会采用两种方式:全部打包成一个jar,或者打包成一个war。现在讲一下打包成jar部署。2.打包成jar第一种方法(idea)1.clean2.package第二种方法(命令行):…

    2022年6月18日
    26
  • 李氏第二法分析稳定性matlab,9-4李雅普诺夫稳定性分析2010.ppt

    李氏第二法分析稳定性matlab,9-4李雅普诺夫稳定性分析2010.ppt9 4 目录李氏稳定性理论的简介向量和矩阵的范数矩阵范数二次型函数及矩阵表示二次型函数的定号性正定的充要条件判断定号性两种方法证明正定系统稳定分类对象及其平衡状态李雅普诺夫意义下的稳定性渐近稳定大范围 全局 渐近稳定性不稳定定理 1 2 3 分析系统渐近稳定例题李雅普诺夫第二方法简介李雅普诺夫函数及稳定性定理在原点渐近稳定几何意义例题定理 3 定理

    2026年1月23日
    3
  • 计算机常用编码方式有哪些_计算机网络无分类编码

    计算机常用编码方式有哪些_计算机网络无分类编码计算机常用编码方式

    2025年7月2日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号