Mosh is a great way to overcome lag and flakey connection issues when accessing remote terminals over SSH: https://mosh.org/
Unfortunately, there's still not a lot of clear documentation for "idiots" because a lot of the existing guides assume a) "it just works", or b) you're already skilled enough to set everything up from scratch (assumed knowledge/use cases).
One of the problems I ran into for quite a long time yesterday was getting the darn thing to connect to my Google Cloud instance. I kept running into the mosh: Nothing received from server on UDP port 60001. [To quit: Ctrl-^ .]
error (by the way - to quit, you have to press . after Ctrl-^ - it's not just Ctrl-^, there is a dot there too!)
FAQs and the like made vague spartan references to NATs, firewalls, iptables and the like and I tried out various commands and configurations on the server and local end (was the NAT on my side the problem? I didn't know!) It all felt like a big drama at the time - what were other people not telling me? What was I not getting?
With a clearer head today, I for some reason decided to dig around to compare cloud pricing between Amazon, Google and Microsoft. I ended up back at my console.cloud.google.com page to try and figure out how much processing/data I was using and what do ya know; I found a link I hadn't previously seen nor cared to notice, next to the Internal IP details (nic0). Hah, it listed firewall rules!
Another click after that (it still wasn't immediately clear how I could create a new rule for mosh), and I was able to find the button to create a new firewall rule.
- Use https://console.cloud.google.com/networking/firewalls/list to create a new a new rule for mosh. Create a new rule for mosh using udp:60000-61000. You shouldn't even need to touch iptables, firewall-cmd or the like within your remote terminal.
- ssh to your instance, run mosh-server.
- Back on your local terminal - if your normal ssh command is ssh username@address, then just type mosh username@address
- That's it. No more, no less - at least for this type of basic set-up.
I believe Amazon EC2 might have a similar process but I didn't get around to looking at those guides. I probably should have done that first before trying to bash around in tmux panes and windows and following iptables red herrings.
If you're using --ssh=COMMAND, do this:
mosh --ssh 'ssh -p 11111' localhost
Rather than:
mosh localhost --ssh 'ssh -p 11111'
Or maybe it was the other way around? Better yet, perhaps try both (along with pkill mosh-server
when you ssh back in. For some reason, both will end up working after the first connection. I'm still trying to figure out why it seems to only work intermittently. It's quite bizarre - turning the firewall off and on, adding a rule, rebooting seemed to be the most reliable way to get it going. It's probably the reboot that is doing the trick to avoid that all-too-familiar mosh: Nothing received from server on UDP port 60001. [To quit: Ctrl-^ .]
message.
Replace localhost with username@domain if you're not playing around between your machine and a VirtualBox instance.
- Go to Devices > Network > Network Settings...
- Under Network/Adaptor 1/NAT, click Advanced and then Port Forwarding
- Rule 1: TCP / Host Port 11111 (or anything you'd like that won't conflict) and Guest Port 22
- Rule 2: UDP / 60000 / 60000
- Rule 3, etc: UDP / 60001 / 60001
Leave the Host IP and Guest IP columns blank. Make sure the 60xxxx ports are the same in both Host and Guest Port columns! For the purposes of testing, remember to either configure the firewall or disable them (sudo ufw disable or sudo systemctl disable firewalld and reboot) and keep passwords short. If you're testing in the cloud, the firewall settings are probably best done via your web browser.
I've tested this with CentOS 7 Minimal as well as Ubuntu 14.04.5 LTS, Trusty Tahr. I specifically went for an older Ubuntu LTS as an experiment, compare and troubleshoot unicode emojis with CentOS 7...
- Emoji such as 🤔
- Although these work: ⚽ and
⚠️ - hmm. - glibc 2.17 on CentOS 7.5 appears to be the culprit - I'm now considering a migration to Debian 9 Stable or Ubuntu Minimal 18.04 LTS...
Update: I'm going to go ahead with a migration to Debian Stable, which should offer a good enough mix of newness and stability. While Debian Stable doesn't have the latest glibc (2.27) at this stage, most emoji I see work with the existing version (2.24). When testing freezes, I should be able to safely update to that and therefore be pretty much as current as Ubuntu LTS (if not more current). Some might quip that Debian Stable is very old, but its update cycle is significantly faster than CentOS!
Update 2: Upgrade from CentOS 7. Either to CentOS 8, or Debian Stable. That'll fix emoji issues.
gcloud compute firewall-rules create mosh --allow udp:60000-61000