Note: This started out as a page about MOSH, but I've moved on to AutoSSH, which is way easier without much configuration, and better at what it does. I had not been aware of Mosh (mobile shell), though clearly its own level of awesome is not a reason for that. Basically it replaces SSH, but still uses it for authentication and the like. > Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes. Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links. Mosh is free software, available for GNU/Linux, BSD, macOS, Solaris, Android, and Chrome. An iOS version is in testing.
Problems with MOSH
There are several problems with MOSH which make it annoying, and in need of repair or replacement.
- First, the cursor tends to jump around making editing inside Nano very difficult.
- Second, the single screen means that multiscreen output from programs (e.g.,
cat, etc.) is impossible, and
| less or other screen-at-a-time options are the only way to capture all output (or
> text | nano text).
Some discussion of these issues and other options:
- New bounty on MOSH prevents the use of scrollback, but the developer's response to this thread is less than encouraging
- See discussion in the issue regarding the use of screen inside of MOSH (I think...)
- Eternal Terminal with compiling issues on RedHat-based distributions, and non-Apple terminal clients on OSX
- AutoSSH - might be a good solution, need to test
Install and Configure AutoSSH
AutoSSH is pretty cool, though not a complete solution (tmux, screen, or something else is needed, to some degree).
- On RH/CentOS/AMI install AutoSSH with standard yum command
yum install autossh
- On OSX,
brew install autossh
Remember, AutoSSH is a client-side solution, so no server install/config is necessary.
Note that regarding the polling, it may be that SSH alone does the polling. I'm still wondering if I really need tmux (or screen) on top of autossh. See:
- VPN-less persistent SSH Sessions, which follows on persistent SSH connections with Context and smux - ssh with auto-reconnect tmux, a mosh replacement.
Note that the ~/.ssh/config` file needs to be configured, and also pay attention to the directives for routing over a particular connection, especially if there are more than one desired.
If AutoSSH works, then there is greater simplicity on the server as special ports, and an application, no longer need to be used.
Install and Configure Mosh (if you AutoSSH doesn't work for you)
Steps to install Mosh, create services file for firewalld, reload and make permanent.
sudo yum install mosh sudo nano /etc/firewalld/services/mosh.xml
Add the following to mosh.xml
MOSH Mosh (mosh.mit.edu) is a free replacement for SSH that allows roaming and supports intermittent connectivity.
reload and restart firewalld
sudo firewall-cmd --reload sudo firewall-cmd --add-service=mosh --permanent sudo systemctl restart firewalld
mosh --ssh="ssh -v -i /full/path/to/privkey" user@server
This essentially replaces the SSH command
ssh -v -i /full/path/to/privkey user@server
SSH has a config file located at
~/.ssh/config which can help speed up connections with directives, such as:
Host HOST RSAAuthentication yes IdentityFile ~/.ssh/HOSTNAME User USER@HOST IdentitiesOnly yes
Identity file directives are usually needed on the command line in many cases, but the
IdentitiesOnly yes helps restrict the public keys attempted in the authentication process.
If you get You have a detached Mosh session on this server, try:
kill $(ps --no-headers --sort=start_time -C mosh-server -o pid | head -n -1)
That will kill all but the latest session (hopefully yours, which you can then exit out of and re-enter).