AutoSSH (and MOSH)

Note: This started out as a page about MOSH, but I've moved on to Auto SSH

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.

https://www.youtube.com/watch?v=XsIxNYl0oyU

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., ls, 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:

Install and Configure AutoSSH

AutoSSH is pretty cool, though not a complete solution (tmux, screen, or something else is needed, to some degree).

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:

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

<?xml version="1.0" encoding="utf-8"?>                                               
<service>
  <short>MOSH</short>
<description>Mosh extends ssh for intermittent connect</description>                         
  <port protocol="udp" port="60001"/>
  <port protocol="udp" port="60002"/>
  <port protocol="udp" port="60003"/>
  <port protocol="udp" port="60004"/>
  <port protocol="udp" port="60005"/>
  <port protocol="udp" port="60006"/>
  <port protocol="udp" port="60007"/>
  <port protocol="udp" port="60008"/>
  <port protocol="udp" port="60009"/>
</service>

reload and restart firewalld

sudo firewall-cmd --reload
sudo firewall-cmd --add-service=mosh --permanent
sudo systemctl restart firewalld

MOSH Syntax

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 Config

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.

Error Messages

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)

or better

pkill mosh

That will kill all but the latest session (hopefully yours, which you can then exit out of and re-enter).

See Also