autossh 的几个小技巧

警告
本文最后更新于 2021-05-07,文中内容可能已过时。

查看帮助,设置环境变量

 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
30
autossh --help

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

可以看到,我们通过设置环境变量,来配置 autossh 的参数

1
2
3
4
5
## 设置日志级别
export AUTOSSH_DEBUG=1

## 设置日志文件
export AUTOSSH_LOGFILE=$HOME/autossh.log

处理 bind: Cannot assign requested address

根据这篇博客的观点,有可能是使用了 IPV6,我们可以强制要求使用 IPV4

1
2
3
4
vim ~/.ssh/config

Host *
    AddressFamily inet

处理经常断线的问题

有可能是 id_rsa 错误了,需要重新生成一份,然后指定 -i 的路径

相关内容

william 支付宝支付宝
william 微信微信
0%