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.