Remote Shell Setup

I was recently talking about the best way to shell on remote machines. The default way that I’ve seen most people run is with just a terminal and SSH. It is simple and very efficient. Nothing to install and configure. All machines will have no issues with that. But once you start requiring a bit more than just running commands, that simple set up will not work well. I needed something that could do all of:

iTerm2

If you are on macOS not using iTerm2, then you are missing out on a lot features that will make your life easier. There’s nothing much to do here except to set terminal type reporting to xterm-256color and enable mouse reporting in the settings. This will allow us get colours and to use the trackpad to click and scroll.

mosh

mosh holds the pieces together. It is a remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes. It’s more robust and responsive than SSH, especially over Wi-Fi, cellular, and long-distance links. You’ll need to install it on both the client and the server.

You can find installation instructions for other operating systems from https://mosh.org/#getting.

For mosh to be able to work, your server needs to open the usual SSH ports as well as UDP ports between 60000 and 61000. If you have less users on your system, you can open a smaller range.

tmux

tmux is a terminal multiplexer. It allows the user to switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. This means that I can be writing text in the first window, chatting on IRC in the second and have a shell prompt on the third. Or split a window into panes and have documentation on the left and write code on the right.

The configuration file. tmux can be configured extensively to your liking. Colours, key bindings, status bar information can all be personalised. On the status bar, I have window control to the left and system status to the right. I use it as a simple snapshot to how the system is behaving while I’m using it.

Putting it all together

With the pieces in place, I can just type mosh remote -- tmux a and get a shell that is just a pleasure to work in.

This setup allowed me to write and publish this blog post from my laptop while flying through the air at ridiculous altitudes and speeds (41,000ft at 500knots). WiFi in an aircraft has extremely high latency. It takes around 800ms RTT to the nearest Cloudflare PoP. And that is when you are able to successfully connect.

I am still amazed at how such high latency was not an issue. If this was done on a normal SSH setup, writing this will not be possible.

Stanley Tan
@stnly