3

I have a PI at home that creates an SSH tunnel to my VPS with autossh so I can access it from my VPS.

When I log in to my PI from my VPS the connection keeps closing (which makes it unusable). For example when I edit a file or even when I cd to another directory, the connection closes.

However if I ssh from my PI to my VPS, the ssh session keeps running and doesn't close.

I would like to have a reliable session from my VPS to my PI

Here is the command I use to connect to create the tunnel:

autossh -M 5233 -N -R 2514:localhost:22 vps -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -i /home/xbian/.ssh/id_rsa

and here is my ssh config on my PI sshd config

  • 1
    Does the connection close while you're using it, or only when you're (briefly, perhaps) not using it. Approximately how long do you get from the time you connect until it closes on you? – roaima Apr 11 '16 at 11:58
  • When I edit a file it closes, or even when I cd to a directory, so I would say it doesn't matter if I'm typing or not. I would say the connection lasts for 1 or 2 minutes, sometimes less than that. – Ben D Apr 11 '16 at 13:34
  • I've added that to the question thank you :) – Ben D Apr 11 '16 at 18:48
  • Are you ssh'ing through the tunnel? If so you'll need the ServerAliveInterval added to that connection as well. Just because the tunnel stays up doesn't mean the connections inside it will as well. Curious as my SSH session are defined with -o ServerAliveInterval=60(they stay up for days typically). Your docs/flavour/distro might be different however. – Techmag Apr 12 '16 at 19:57
  • 1
    I found the -M option of autossh to be unreliable and always use -M 0 and let SSH do the connection monitoring (with TCPKeepAlive yes (or "no" for interactive connections) and ServerAliveInterval=30). – ckujau Apr 13 '16 at 18:49
0
+50

I found the -M option of autossh to be unreliable and always use -M 0 and let SSH do the connection monitoring, along with TCPKeepAlive=yes (resp. "no" for interactive connections) and ServerAliveInterval=30.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.