mosh : The answer to ssh annoyances

I got to know about mosh recently from a tweet by gaveen. Mosh is a replacement to the good old ssh command. It solves some of ssh’s biggest annoyances.

mosh handles connections internally

When you’ve ssh’ed to a server and your internet suddenly drops, that ssh connection gets broken. With mosh, you wouldn’t have to worry about this because it will silently connect you back to the server once the internet is back and you won’t even know. So even if you sleep the computer, when you wake it up again the connection would be back on just as you left. When you open up your laptop in a meeting or a conference, that connection will still be there. I haven’t closed one mosh connection to the Best At LK server in more than a month!

mosh echoes keypresses instantly

Another headache with working on ssh connections is the lag while typing. If you type in something it will take some moments to reflect, which can be really annoying. Mosh’s work around for this is giving an instant response to typing. 90% of the time, what the server would do is just echo the key you typed. So why not do that without waiting for a response from the server? Mosh underlines those keystrokes till the response comes, so you would know. Rest of the time when the keypress does something else, mosh would adjust accordingly after the response comes.

Getting started

If you use a debian-based distro (like Crunchbang or Ubuntu), you can install mosh with apt-get.

sudo apt-get install mosh

For other distros and operating systems, the homepage has installation instructions.

If you’re feeling rather adventurous, or you’re the type that needs to stay in the edge, you can clone the mosh git repo and build it. The build instructions are in the home page as well.

Note that you have to install mosh in your server as well. Worry not, it doesn’t run as a daemon. It starts up only when you connect to the server.

Now ssh to the server using mosh, instead of ssh.

mosh user@111.222.333.444

Mosh respects ~/.ssh/config as well! So you can continue using your favorite aliases.

Gotchas

Mosh needs to open a UDP connection. In an ordinary vps this wouldn’t be a problem, but if it’s an important production server the server admin might not be willing to open up a UDP port. If you don’t have any contact with the admin, you might be out of luck.

In Amazon EC2 instances, the UDP ports are usually closed at the beginning. To open them up, add a ‘Custom UDP Rule’ in the Security Group settings in EC2 dashboard. In the rule, set the range of ports as 60000-61000.

Colombo Show HN Meetup

Update: Parinda has more to say about the meetup.

We had a small Colombo Show HN Meetup this weekend.

Show HN
The plan was to hold a Colombo Hacker News meetup. Then we thought it’s better to make it a Show HN meetup, where participants show some work they’re doing to the audience, explains the developer stories behind it and the crowd gets into a constructive discussion. A meetup of this nature is more engaging and actually worthwhile to everyone, unlike most of the meetups where two or three individuals do ‘talks’ and the crowd applauds in approval. More often than not, constructive criticism never takes place as the audience is rarely willing to comment or ask questions, at least here in Sri Lanka.

So a handful of us got together and organized a small, invite-only meetup this Saturday.

First to show his work was Chethiya. He demonstrated a browser extension which he calls the Web Task Switcher. He’s trying to solve the problem of tab overload in browsers. We open a new tab to search for one thing, then go on and on, clicking on interesting links we find, finally ending up with dozens of tabs and not really finding what we searched for either. Chethiya’s extension identifies this behavior, breaks down multiple searches into tasks and lets the user ‘switch’ between, save and close the tasks. At the moment, the project is available only for testers in the Chrome Web Store and will be released soon.

Next up was Thameera (which, funny enough, happens to be me). I demonstrated how grunt was used in several of my projects to automate the compilations, builds and testing. Half of the discussion was spent showing how cool zsh was though, which is much, much more important than automating your workflow IMNSHO.

Chanux walked us through configuring an nginx server using Lua, and using redis to store the redirections. This way the system admins no longer need to edit configuration files and restart nginx each time a new redirection is added or updated. A demonstration was done using a server placed in a Docker instance. Chanux is hoping to open-source the project, which he calls Rusty, some time in the future.

Then came Parinda explaining his newest frontend Javascript framework Sweet.js. Yes, there’s already another popular Sweet.js library out there and Parinda’s considering renaming it to a new name. (God bless him trying to find a name not used as a JS project). Sweet looks both like a cut down version and an improved version of Backbonejs. It’s lighter than Backbone as Sweet doesn’t implement sync or event handling. But it adds some useful functionality like multiple inheritance for models/views and an improved router, which supports HTML5 history states. It’s used in production at Forestpin and Nearby.lk and is freely available at Github with an MIT license. An annotated source that uses litcoffee can also be found there.

Chathuras then showed the Javascript charts plugin he’s creating. It uses RaphaelJS to render the charts as vectors, so this would work even in old browsers like IE 7. Since the computations involved can be frustratingly slow in older browsers, the pixel values for the graphs are calculated in the server and sent to the frontend library. We went on to talk about how worthwhile it is to focus on older browsers and choosing a single selling point that would make the library go viral.

We are hoping to have regular Show HN meetups, at least once a month. Most probably we’ll be increasing the number of invitees each time while making sure it doesn’t turn up to be a regular, one-person-talks-others-just-listen meetup. A meetup where you can show what you’ve made to like-minded developers, get their honest feedback, and learn from what others are doing.