Tech, Toys, and Tidbits

After reading about Mosh (Mobile Shell) I had to give it a try.  This is truly SSH for the modern age.  Connections STAY connected even when your IP changes, or you roam from network to network.  You can put your laptop to sleep while connected, carry it to work, open it up, and the connection is still live.  Amazing!

  1. Mosh on the server(s)
    • This part is easy.   Follow the instructions from the Mosh site for your distro.  Since I’m running Ubuntu 12.04 it was as easy as “sudo apt-get install mosh” but it will vary from distro to distro.
    • You may have to open some holes in your firewall – I had to do a “sudo ufw allow proto udp to any port 60000:61000” to let Ubuntu listen on the req’d ports. 
    • You’ll also need SSH access to your server, as the initial authentication + initialization of the Mosh session is handled via SSH.
  2. Cygwin
    • Also Easy.  Download the setup.exe from Cygwin, and run it.  There are a few extra packages you’ll need in order to compile Mosh for Windows, so make sure you select:
      • make
      • boost
      • libncurses-devel
      • pkg-config
      • and perl
  3. Mosh for Cygwin
    • This bit requires some compiling, but don’t be nervous.  Step by step instructions are at Gisthub.  We’ve done steps 1+2 already, so start from 3.
  4. Putty (Or Kitty!)
    • Download and install Putty, or Kitty if you prefer.  Kitty is a fork of the most recent Putty with a bunch of new features – like transparency settings for the windows.
  5. PuttyCyg Plugin
    • If you use Putty then grab this, or if you’re on Kitty then grab this.  Extract it in the same folder as the Putty/Kitty executable.
  6. Putty profiles
    • Last stretch!  There are a few things you need to do here.
      1. First, you’ll need to add c:\cygwin\usr\local\bin\ and c:\cygwin\bin to your path. 
        1. Open the start menu
        2. right click on Computer
        3. Click Advanced System Settings
        4. Click the Environment Variables button on the Advanced tab
        5. Under System Variables select “Path” and add “;c:\cygwin\usr\local\bin\;c:\cygwin\bin” to the end.  MAKE SURE YOU DON’T DELETE ANY THING – JUST ADD THE CYGWIN PATHS TO THE END
      2. Now, open Putty/Kitty. 
      3. Select PuttyCyg as the connection type
      4. enter “mosh” as the command – where is the host you want to connect to.
      5. Hit Open
  7. You’re now connected via Most to your host thru Putty/Kitty!  Yay!  SSH that’ll stay connected no matter how you move about from IP to IP.
  • Sweet!  Thanks for the info.  Just what I was looking for.

  • Great article, the problem David Borg describes still exists.

    Just replace the content of the file /usr/local/bin/mosh with then it works.
    /usr/local/bin/mosh with then it works.

  • Pingback: MoSH: mobile shell | Dem Commander1024 sein Blog()

  • EpaL

    Love this article but for some reason, I just cannot get this to work. Following the instructions above (including downloading the ‘fixed’ mosh perl script) I always get the following error:

    mosh: Permission denied

    followed by a dialog “Connection closed by remote host”.

    I’ve tried running Kitty as an admin (Windows 7), changing the command to env perl /usr/local/bin/mosh hostname and a number of other things but no matter what I do it just refuses to work.

    Has anyone else run into this issue?

    • Rob

      Yes, I had exactly the same problem, also I could not get the standard kitty cygterm option to work, and it never appeared for me in putty. It would seem that mosh works fine from inside a cygwin terminal but not when called via the helper. It seems to want some environment setting up first? Anyway, puttycyg is no longer being maintained, so I found a good workaround:

      – Download the UNIX putty source and compile the contrib/cygtermd

      Once set up as instructed, you can make a putty “session” that just opens a cygwin.
      It’s also quite handy to have a session in putty for cygterm, as it’s a much more full-featured terminal, and you can just call it from the same putty session menu.

      There might be a more elegant way to do this, but I had similar env problems trying to get mosh to exec ssh itself. So I just made a shell script within the cygwin home directory that runs mosh with the correct parameters.

      My putty “proxy command” is:

      c:cygwin64bincygtermd.exe /home/robl /bin/bash -l -c “/home/robl/ %user %host”

      For %user to work correctly, put your username in the Username: field on the PROXY config page.

      For %host to work correctly specify the actual host name to connect to in the session config (not just localhost or anything as for the cygterm instructions…)

      Then the contents of “” is:

      echo “logging on to $2 as user $1…”
      cd /home/$1
      /usr/local/bin/mosh $1@$2 –server=”LANG=en_GB.UTF-8 mosh-server”

      (Change to suit obviously!)