Keeping SSH connections alive on iOS with high-fidelity terminal emulation and without draining your battery: the Story of El Preservador.

https://blog.xibbon.com/solving-background-disconnect-issues-on-ios-with-el/

El Preservador: SSHing Responsibly on iOS

With La Terminal, we strive to offer an SSH client that just works on iOS. With this in mind, I set out to make design decisions on behalf of users that would provide an experience that works out of the box while providing the best terminal emulator experience they deserve.

Xibbon Blog

@Migueldeicaza if I actively exit/logoff, should the preserver not exit completely?

It isn't for me, and it's not being reused when a new connection is made, so if you disconnect cleanly and reconnect each time you end up spawning another preserver....

@interpipes it should terminate if you end the session. If this is happening, I have a bug. What OS is the target, and shell you are using?
@Migueldeicaza Debian 11(.6) x64, currently running 5.10.0-20-amd64, regular plain old bash
@interpipes thanks, let me test that configuration. Btw, it will die after 16 hours or 12 idle hours - I can’t remember the exact number

@Migueldeicaza I was worried perhaps it was some weird interaction with docker running on the first host, but it behaves the same on another very plain Deb11 server.

A third Deb11 server (this one is admittedly.... special), the shell never starts, I just get connection log that ends in "The initial connection to the preservator has now closed" and no launched background process. I can't see any evidence of the preservator attempting to "re-ssh" to localhost... how would I generate more debug?

@interpipes for that one, could you run: .laterminal/session.*3 --version I suspect a very old Debian that can’t run the binary perhaps?

@Migueldeicaza it's a Deb11 host like the other two.

The binary itself ran ok;
preservator bb60eb8d1c369f26cb7b1767b40ccf924d6ab977

I only said this one is "special" because it is a legacy OSE which was previously a 32-bit that I did an in-place switch to 64-bit a while ago. I straced the binary and it's pulling in x64 libc, though, so no, it's not related to that.

Then I figured it out, by trying to manually SSH to 127.0.0.1 - this sshd is only listening to specific IPs. πŸ€¦β€β™‚οΈ

@Migueldeicaza I don't know if it's worth having a fallback attempt to ssh to the same IP the LaTerminal client is connecting to rather than localhost to avoid non-standard ListenAddress configurations, but I guess there's also a non-zero risk that might just end up bouncing off firewall rules anyway.

(plus I guess it is maybe less useful where that IP is dynamic in some way, if it changes then the preservator session will be lost.. I guess if that fallback was used, print a warning?)

@interpipes I definitely should add a warning and improve the error reporting on that code path. I just added a few bits to notify the user of the problem, but I am missing crucial information. I should report β€œfailed to connect to machine:port” to aid in diagnosis