I remember when mosh first came out and thinking "that sounds like a great idea, maybe I'll set it up sometime" and then never getting around to it. Several times over the years I've thought similarly, but it never seemed worth it. A week ago a coworker asked if there were good tools for handling remote terminal use over laggy internet connections, and I suggested mosh. They really liked it, which then had me feeling silly for never trying it, and got me to actually do it. So: I'm typing this over mosh, and it's excellent! I should have done this years ago.

With a traditional remote shell like ssh you are sending characters back and forth and the state of your terminal is maintained client-side. This means that when you press a 'q' you don't see it appear on the screen until a message has gone to the server saying "they pressed 'q'" and a response comes back saying "ok, put a 'q' on the screen". If you have a nice fast connection this happens so quickly you can't even tell, but if you're on flaky wifi it can be very painful.

Mosh turns this around, maintains the terminal on the server, and syncs the state of the terminal from the server to the client as efficiently as it can. Additionally, it echos your typing back as you go, and then overwrites it with the state from the server once it gets it. It even handles cases where you're typing text into the middle of an existing line, sliding the rest of the line forwards to make room. It shows locally echoed text with a little underline so you know it's just a prediction.

Working from my third floor bedroom connected to wifi in the basement, in a house with seven other people who might all be streaming video at once, with a workflow that is built entirely around being ssh'd into a remote server, this is just amazing.

It's funny looking back at the world before, and seeing people being dismissive of these ideas. For example, about six months before mosh came out someone asked on StackOverflow how to avoid the typing delay on SSH. The accepted answer is saying this is impossible and just suggesting that people type without seeing feedback (this probably works a lot better for people who are more accurate typists than I am). Similarly, the HackerNews discussion has several people saying that you can patch something similar together with existing tools.

This does leave me wondering whether mosh could make better predictions. When I hold down the up arrow, it only slowly moves my cursor from line to line, waiting for server round trips. Since mosh has my whole terminal state, it can probably figure out that I'm typing this in emacs from the minibuffer and how previous arrow keys and emacs keybindings were handled. It would be really neat if it could then use those predictions to let me navigate vertically as easily as horizontally. Similarly, when I type Alt-X emacs moves me to the minibuffer: after seeing a few rounds of this it seems like a fancy prediction system for mosh could do this as well? You would need to be careful about not echoing passwords, but I think that's still doable? I'm curious whether anyone has explored this direction, though for now I'm really very happy with its current abilities.


10 comments, sorted by Highlighting new comments since Today at 5:42 AM
New Comment

It's probably unrealistic to try to mash together mosh and DeepTabNine or something, but if you spend a lot of your time working in Emacs, have you tried using its many remote-file-editing capabilities to run it locally rather than on the remote box? That greatly reduces the impact of any network issues.

I should have done this years ago.

Working from my third floor bedroom connected to wifi in the basement, in a house with seven other people who might all be streaming video at once, with a workflow that is built entirely around being ssh'd into a remote server, this is just amazing.

Here too, instead of suffering a death by a thousand cuts (how does one run out of socks? One day at a time), have you considered running an Ethernet cable down? I have twice been in similar situations, and both times I found it well worth my while to run an Ethernet cable to avoid the latency and unreliability of WiFi (even when that required digging a trench for 50 feet). EDIT: https://www.lesswrong.com/posts/mdcXfbiEe6mq2qXPa/ethernet-is-worth-it-for-video-calls

A few dozen hours at most spent practicing your touchtyping is also probably something you would've benefited from doing years ago, but still would now.

I've considered it, and have done similar things before, but I'm also really worried about touching the networking setup at all in any way because of how dependent we are on it right now. The likelihood of breaking something is low, but the benefit if I succeed isn't all that high.

Ethernet cable is way more reliable than WiFi (a major reason I install it, to just make all of those occasional glitches and disconnections and mysterious gremlins go away), and also pretty much impossible to screw up installing. You plug one end into each device. Not even a password to set up.

I've worked with ethernet a lot. I'm nervous to the point that I don't even want to plug a new cable into the cable modem (which is also an ethernet switch). The cable modem is supposedly some sort of special one that we can't replace ourself, so if it breaks we have no wired internet for however long it takes our cable company to get us a new connection.

I was considering getting a redundant cable connection (our building can get both Comcast and RCN) but that would involve letting a cable tech into the basement which I'd also really not like to do right now.

Other things I could do include moving the WiFi box up from the basement (the cable from RCN is long enough to reach the second floor) but again that is risky.

(This is not a way I'm used to thinking: normally I just do things and expect that in the unlikely event that it goes wrong I'll be able to buy what I need to fix it. But covid changes that.)

This is overstating the risk. I should do it.

Done. It's nice and I didn't break anything.

Another reason this didn't make sense before is that I didn't have a desk at home, and used my laptop from a lot of different places. But now that I'm working remotely full time I have a place where my laptop is 80% of the time and where I can easily go if my video calls aren't working well.

If a failure in connection is really that perilous, sounds like another thing you should've done years ago - and setting up a backup Internet connection as well (used to be you might get a DSL or T1 backup connection if you worked from home and really couldn't afford any interruptions, but these days it can be as simple as making sure you can set up your smartphone as a hotspot). The other two suggestions remain.

We have backup internet via tethering to our phones or else I would have got an extra line to our house in early March. But it would still be really inconvenient to work this way, since 4G is not as good as high speed cable and phones aren't great at this.

Your personal blog tags this as terminal but not shell, which also exists. You may wish to merge those tags.