SSH tunnel opened with autossh closes every few days

3

1

I keep an ssh tunnel open with autoSSH. Every few days the tunnel seems to sporadically close.

I do a ps -ef | grep autoSSH, and autoSSH is still running. Occasionally autoSSH will output

Warning: remote port forwarding failed for listen port 52698

Also, I run autoSSH with nohup. Does anyone have any ideas? Or does anyone know what I could do to debug this?

user2588667

Posted 2013-09-06T15:37:17.463

Reputation:

Have you tried another Port than 52698? I remember ports 50000 upwards are heavily used by the OS. I suggest running autossh inside "screen" instead of using nohup. – Tim Haegele – 2013-09-06T18:32:50.470

ahhhh sorry, I copy/pasted that line from somewhere, the port im using is 2343. Is there any reason you suggest using screen instead of nohup? – None – 2013-09-06T18:42:39.200

Answers

1

Sometimes the client thinks the connection has died, and tries to reconnect, but by that time the server still has the port busy, and cannot open it again for the second sshd process. Then, the previous process dies, but the connection is not retried. This has, as far as I know, no easy solution with ssh.

If the only purpose of your ssh session is to keep tunnel connections alive, you do not need screen or nohup. It would be cleaner to use -N (run no commands) and -f (fork just after setting everything up).

As you can see in the manpage of autossh, autossh intercepts this -f and yields the expected behaviour.

Raúl Salinas-Monteagudo

Posted 2013-09-06T15:37:17.463

Reputation: 1 058