ssh - autossh退出,因为ssh(dropbear)无法解析主机

标签 ssh dns autossh

我在可能具有Internet连接或没有Internet连接的系统上运行autossh。我真的不知道它什么时候有连接,但是如果是这样,我想通过以下方法使autossh建立ssh隧道:

autossh -M 2000 -i /etc/dropbear/id_rsa -R 5022:localhost:22 -R user@host.name -p 6022 -N

几秒钟后,它抛出:
/usr/bin/ssh: Exited: Error resolving 'host.name' port '6022'. Name or service not known

就是这样。 autossh难道不是无论如何都可以保持ssh进程运行吗?我是否真的需要通过ping来检查连接?

最佳答案

您需要将AUTOSSH_GATETIME环境变量设置为0。从autossh(1):

Startup behaviour
 If the ssh session fails with an exit status of 1 on the very first try, autossh

 1.      will assume that there is some problem with syntax or the connection setup,
         and will exit rather than retrying;

 2.      There is a "starting gate" time. If the first ssh process fails within the
         first few seconds of being started, autossh assumes that it never made it
         "out of the starting gate", and exits. This is to handle initial failed
         authentication, connection, etc. This time is 30 seconds by default, and can
         be adjusted (see the AUTOSSH_GATETIME environment variable below). If
         AUTOSSH_GATETIME is set to 0, then both behaviours are disabled: there is no
         "starting gate", and autossh will restart even if ssh fails on the first run
         with an exit status of 1. The "starting gate" time is also set to 0 when the
         -f flag to autossh is used.
 AUTOSSH_GATETIME
         Specifies how long ssh must be up before we consider it a successful connec‐
         tion. The default is 30 seconds. Note that if AUTOSSH_GATETIME is set to 0,
         then not only is the gatetime behaviour turned off, but autossh also ignores
         the first run failure of ssh. This may be useful when running autossh at
         boot.

用法:
AUTOSSH_GATETIME=0 autossh -M 2000 -i /etc/dropbear/id_rsa -R 5022:localhost:22 -R user@host.name -p 6022 -N

关于ssh - autossh退出,因为ssh(dropbear)无法解析主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32701821/

相关文章:

ssh - 如何在Ansible命令中传递用户名/密码

ubuntu - Docker容器访问本地DNS

linux - 启动时重新启动 autossh 反向隧道的问题

bash - 如果连接超时、ip、端口不存在或不使用 ssh 和 sshd 配置文件进行响应,我该如何退出、停止、终止 autossh?

python - 在 python 中执行时 autossh 不工作

ssh - 在 PuTTY 命令行上指定私钥

bash - 如何从远程主机获取最后 10 分钟的日志

android - 使用主机名对本地计算机进行 Http 请求在 Android 设备中不起作用

google-app-engine - 使用 Google App Engine 或 ZoneEdit 在裸域上设置 OpenID 委托(delegate)

ssh - 为 AWS EC2 实例创建私钥