Live data from Hacker News

Ask HN: moving beyond screen to persist SSH sessions?

news.ycombinator.com

1–10 of 36 posts

Ask HN: moving beyond screen to persist SSH sessions?

#1
I work from my laptop, and my laptop is constantly moving between my home, cafés, libraries, schools, etc. I have SSH windows open and I want them to simply stay open and work all the time. I want the session to automatically persist changes in wireless networks, temporary lack of network connectivity, putting my laptop in suspend, etc. I also want my SSH-forwarded ports to keep being forwarded as long as I'm connected to the internet. It's such a huge pain to constantly re-login to all my SSH windows on every minor blip of connectivity.

Is there any way to accomplish this in any OS? Every time I have posted this problem elsewhere, everyone shouts "screen!" but I think the HN audience understands that while screen is cool, it doesn't even come close to resolving this issue; so I'm hoping for a better answer here.

To give an example of my problem:

Let's I have 5 SSH windows open doing various things (perhaps I am running top, emacs, a window that i'm using to type svn commands, etc). I also have port-forwarding set up so that I can use Firefox securely through a SOCKS proxy, and access websites that are only available from behind the SSH machine.

If my wireless network switches or even drops for 1 second, I now have 5 dead SSH sessions. I have to somehow reinitialize them, and when I do it's a mess to get them back in the correct state. I can solve the latter with screen. How can I solve the former automatically, without wasting time re-establishing those connections?

Re: Ask HN: moving beyond screen to persist SSH sessions?

#3
You have to run your screen session from a stable host, not a laptop that gets disconnected all the time. Do you have a web host with ssh access? A buddy with a VPS somewhere? A spare $5 a month to spend on a shell account host to never have to deal with this again?

You could try using ssh-agent to reduce the pain of your connectivity issues, but screen really is the answer.

Re: Ask HN: moving beyond screen to persist SSH sessions?

#4
post #3

You have to run your screen session from a stable host, not a laptop that gets disconnected all the time. Do you have a web host with ssh access? A buddy with a VPS somewhere? A spare $5 a month to spend on a shell account host to never have to deal with this again? You could try using ssh-agent to reduce the pain of your connectivity issues, but screen really is the answer.

I have plenty of access to shell accounts. But using a shell account to screen to another host just adds another layer of complexity, because when I lose my wi-fi connectivity for 1 second, then my SSH session to the shell account is lost instead of access to the real host. It still requires a waste of time logging into the shell account.

Re: Ask HN: moving beyond screen to persist SSH sessions?

#5
To fix constantly re-logging in to ssh: - set up key authentication and run ssh user@host with your favorite parameters in a loop (shell script) so it reconnects when disconnected. - in fact, have it run screen when connected, so you get right back to where you were effortlessy.

As for port forwarding, you will still be disconnected from everything on connectivity blips when ssh has to reconnect if you use ssh port forwarding. Try a VPN setup instead. You might have to fiddle with the host to keep it from sending RST's/FIN's as soon as you drop (though it shouldn't unless a packet for you comes in during the blip, I think). When you come back, if you come back soon enough, the connections should be restored without having been disconnected. (AS LONG as you have the same IP address on the VPN, so use a static IP setup)

Also, if you run your SSH -through- the VPN connection and recover quickly enough SSH shouldn't disconnect at all either.

More Edit: For long connectivity lapses (changing locations) all your TCP connections -will- drop. This is not something you can work around.

Re: Ask HN: moving beyond screen to persist SSH sessions?

#6
post #2

A VNC or RDP session running on a stable host somewhere, running full screen on your laptop, so you only have one thing to reconnect to. What you want would be cool but it can't be done with TCP/IP.

VNC would be painfully slow, though.

it can't be done with TCP/IP. It surely can, but would have required someone to figure it out. Surely a combination of an SSH client which reconnects (and therefore temporarily remembers your password/key) with screen might do it. But I'm hoping someone has been in the same situation and has figured out a somewhat elegant solution.

Re: Ask HN: moving beyond screen to persist SSH sessions?

#7
post #3

You have to run your screen session from a stable host, not a laptop that gets disconnected all the time. Do you have a web host with ssh access? A buddy with a VPS somewhere? A spare $5 a month to spend on a shell account host to never have to deal with this again? You could try using ssh-agent to reduce the pain of your connectivity issues, but screen really is the answer.

I have plenty of access to shell accounts. But using a shell account to screen to another host just adds another layer of complexity, because when I lose my wi-fi connectivity for 1 second, then my SSH session to the shell account is lost instead of access to the real host. It still requires a waste of time logging into the shell account.

I think you may be constraining the solution down into impossibility. When you lose the network, you will lose the SSH sessions. Period. TCP will guarantee that. (Although not at "one second".) That's part of TCP's point.

The best you can hope for is either to set some stuff up as described so SSH automatically relogins to a screen session, or find a better network connection. Fundamentally, you can't patch around a bad network connection.

Re: Ask HN: moving beyond screen to persist SSH sessions?

#8
post #2

A VNC or RDP session running on a stable host somewhere, running full screen on your laptop, so you only have one thing to reconnect to. What you want would be cool but it can't be done with TCP/IP.

VNC would be painfully slow, though. it can't be done with TCP/IP. It surely can , but would have required someone to figure it out. Surely a combination of an SSH client which reconnects (and therefore temporarily remembers your password/key) with screen might do it. But I'm hoping someone has been in the same situation and has figured out a somewhat elegant solution.

You'd get bogged down in retransmit backoff before you knew it!

Re: Ask HN: moving beyond screen to persist SSH sessions?

#9
post #5

To fix constantly re-logging in to ssh: - set up key authentication and run ssh user@host with your favorite parameters in a loop (shell script) so it reconnects when disconnected. - in fact, have it run screen when connected, so you get right back to where you were effortlessy. As for port forwarding, you will still be disconnected from everything on connectivity blips when ssh has to reconnect if you use ssh port f…

Thanks for your response. Just to clarify, I don't care if my forwarded TCP connections drop when my internet connection drops, just that they are re-established automatically. I also don't care about the actual TCP connection dropping, I just want all my SSH terminals to automatically pick up where I left off. Of course screen factors into this, but it has to be more than just screen.

Regarding the VPN, could this connection be automatically established upon joining a wireless network? (i think you see where i'm going with this question)

Re: Ask HN: moving beyond screen to persist SSH sessions?

#10
post #7

Earlier quoted context omitted.

I have plenty of access to shell accounts. But using a shell account to screen to another host just adds another layer of complexity, because when I lose my wi-fi connectivity for 1 second, then my SSH session to the shell account is lost instead of access to the real host. It still requires a waste of time logging into the shell account.

I think you may be constraining the solution down into impossibility. When you lose the network, you will lose the SSH sessions. Period. TCP will guarantee that. (Although not at "one second".) That's part of TCP's point. The best you can hope for is either to set some stuff up as described so SSH automatically relogins to a screen session, or find a better network connection. Fundamentally, you can't patch around a…

Hmm, I think I just mis-stated my problem as being more difficult than it really is. I posted an example to the question for clarification.
Post reply on HN