How To Install and Use Mosh on a VPS
mhrsntrk / August 10, 2021
mosh is a very powerful ssh extender, especially when you are accessing your VPS over mobile network or different public access points. I will only cover how to install it on a Ubuntu VPS and how to use it effectively.
Installation
In order to use mosh you need to first install it on both the client and the server.
On Client:
If you are using a portable device like iPad so you can easily use Termius or Blink.sh. But, if you want to use mosh on macOS you can install it using Homebrew by using below command.
brew install mosh
On Server:
Installing mosh on Ubuntu is pretty straightforward you can use below commands to install it on your server.
sudo apt-get update
sudo apt-get install mosh
Configuration
Firewall:
You probably setup a basic firewall on your server using UFW. In order to use mosh you need to open UDP ports from the range of 6000 to 6100. You can use below command to do that.
sudo ufw allow 60000:61000/udp
macOS:
mosh work on UTF-8. So in order to connect to a server using mosh you need to set your LC_CTYPE
to en_US.UTF-8
. You can check it using below command.
locale
If it is set to en_US.UTF-8
you can jump to other section if it is not you can add below command to your .zshrc
or .bashrc
and reload.
export LC_CTYPE=en_US.UTF-8
Usage
Since mosh is an extender for ssh, as you can imagine it has a very similar usage. You can use below command to access your server using mosh.
mosh username@server_ip
mosh connection stays connected until you close it so in order to close to connection just write exit
and hit enter!