之前用 autossh 的時候,只是簡單的用了一個 -N 參數。結果遇到一開始沒聯上網或者中途斷網都仍是起不到重連的做用。session
後來在這兒
http://www.oschina.net/translate/automatically-restart-ssh-sessions-and-tunnels-using-autossh
看了才知道原來要加一些參數的。ssh
export AUTOSSH_PIDFILE=/var/run/autossh.pid export AUTOSSH_POLL=60 export AUTOSSH_FIRST_POLL=30 export AUTOSSH_GATETIME=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
-M 0
的意思在 man 裏面是這樣寫的:this
Setting the monitor port to 0 turns the monitoring function off, and autossh will only restart ssh upon ssh's exit. For example, if you are using a recent version of OpenSSH, you may wish to explore using the ServerAliveInterval and ServerAliveCountMax options to have the SSH client exit if it finds itself no longer connected to the server. In many ways this may be a better solution than the monitoring port..net
大概意思是這是一種比較好的用法。。rest