2015-09-21 45 views
1

我在可能具有互聯網連接的系統上運行autossh,或者可能沒有。我真的不知道什麼時候它有一個連接,但如果是這樣我想autossh通過建立SSH隧道:autossh因爲ssh(dropbear)無法解析主機而退出

autossh -M 2000 -i /etc/dropbear/id_rsa -R 5022:localhost:22 -R [email protected] -p 6022 -N 

幾秒鐘,它拋出後:

/usr/bin/ssh: Exited: Error resolving 'host.name' port '6022'. Name or service not known 

而且完蛋了。不是autossh意味着保持ssh進程無論如何運行?我真的必須通過ping左右來檢查連接嗎?

回答

2

您需要將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 [email protected] -p 6022 -N 
+0

稀釋確定。所以在前面加上'-f'或者在前面加上'AUTOSSH_GATETIME = 0'將會修復。謝謝! – milkpirate