Mosh is a fantastic alternative for standard SSH. While SSH uses the TCP protocol, it uses a session bound to IP address, so it is not suitable for roaming. MOSH, on the other hand uses the UDP protocol and app level sessions. This lends itself to roaming.
If you are not on a great WiFI connection, or you sometimes switch between different networks, or your laptop goes to sleep, you will lose your connection on a standard SSH connection. Not with MOSH. In addition, Mosh works significantly batter on connections with higher latency.
Before using it on the client side, you need to insall it on your local machine: mosh.org (free).
Personally, I use a terminal app called Termius, with I find to be the best out there by far. It supports both SSH and Mosh (plus telnet & SFTP), plus all sorts of other fantastic features you will not find in a standard terminal. It also boasts a really attractive UI to work in. There are versions for Mac, Windowsm Linux, iOS and Android, and the free version is excellent. If you decide to opt for the paid version (well worth it in my opinion), you can get auto syncronization between your devices, SFTP, and Snippets (I could not live with out them). There is also a more advanced "Teams" version for sharing among team members. You can check it out here: Termius.
Let's start by making sure everything is current:
$ sudo apt-get update && sudo apt-get upgrade -y
Next install Mosh:
$ sudo apt install mosh -y
Configure the Firewall to allow Mosh. In this case we are using ufw, so adjust as needed if you are using a different firewall:
$ sudo ufw allow 60000:61000/udp
So, for example, if you are using iptables:
$ sudo iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT
That's it! You can now connect using Mosh.
If you are using Termius, you will see there is a Mosh option for every host. Just turn it on, and you qre good to go. If you downloaded a Mosh client and installed it, rather than conneting using the ssh command, you use mosh like this using the client:
$ mosh email@example.com
If you changed your ssh server to a different port (If not, click here to see how), you will connect like this:
mosh firstname.lastname@example.org --ssh="ssh -p 5757"
(assuming you chose 5757 for your ssh port on your server).
And now we are done! Enjoy!