Mosh (mobile shell) is a remote terminal application that keeps your SSH connection alive across network changes, IP address changes, and sleep/wake cycles. It is ideal for VPS users who work from unstable Wi-Fi, travel, or need to maintain long-running sessions without dropouts. This guide walks you through installing Mosh on your VPS and using it from your local machine, including setup, common pitfalls, and troubleshooting.
What You’ll Need
- A VPS running Linux (Ubuntu, Debian, CentOS, Fedora, or similar) with SSH access.
- Root or sudo privileges on the VPS.
- A local computer (Windows, macOS, or Linux) with an SSH client installed.
- UDP port 60000-61000 open on your VPS firewall (Mosh uses these ports by default).
Step-by-Step
- Install Mosh on the VPS. SSH into your VPS and run the package manager command for your distribution. For Ubuntu/Debian:
sudo apt update && sudo apt install mosh. For CentOS/RHEL:sudo yum install epel-release && sudo yum install mosh. For Fedora:sudo dnf install mosh. Confirm installation withmosh --version. - Open the UDP ports in the firewall. Mosh uses UDP ports 60000-61000. If you use UFW (Ubuntu):
sudo ufw allow 60000:61000/udp. If you use firewalld (CentOS):sudo firewall-cmd --permanent --add-port=60000-61000/udpand thensudo firewall-cmd --reload. If you have a cloud provider firewall (like AWS Security Groups or DigitalOcean Cloud Firewall), add a rule to allow inbound UDP on those ports. - Install Mosh on your local machine. On macOS:
brew install mosh(requires Homebrew). On Windows: use WSL (Windows Subsystem for Linux) and install viasudo apt install mosh, or use the MSYS2 package. On Linux: use your package manager, e.g.,sudo apt install moshon Debian/Ubuntu. - Connect using Mosh. The basic syntax is
mosh user@your_vps_ip. Mosh will automatically start an SSH connection, authenticate, and then switch to the UDP-based protocol. If you use a non-standard SSH port, specify it withmosh -p 2222 user@ip(note: this sets the SSH port; the UDP ports are still 60000+). - Use Mosh like SSH. Once connected, you’ll see a normal terminal prompt. You can run commands, use nano/vim, and even run tmux or screen inside Mosh. The key difference is that Mosh handles network interruptions gracefully; if your Wi-Fi drops, the session stays alive and reconnects automatically when you’re back online.
- Disconnect properly. To end the session, type
exitor press Ctrl+D. Mosh will close the connection cleanly.
Common Mistakes
- Forgetting to open UDP ports. Mosh requires UDP, not TCP. If you only opened TCP port 22, Mosh will connect via SSH but then fail to establish the UDP channel, and you’ll see an error like “mosh: Nothing received from server on UDP port 60001.”
- Using Mosh without SSH key authentication. Mosh relies on SSH for the initial handshake. If you don’t have SSH keys set up and require a password, Mosh will prompt you for the password, but it may be less convenient. Set up SSH keys for smoother use.
- Assuming Mosh works over TCP. Mosh is UDP-only. If your network blocks UDP (some corporate networks do), Mosh won’t work. In that case, stick with SSH or use a VPN.
- Not installing Mosh on both ends. You need Mosh on both the client and the server. If you only install it locally, you’ll get a “mosh: command not found” error when trying to connect.
Tips
- Use Mosh with tmux or screen. Even though Mosh is resilient, combining it with tmux gives you persistent sessions that survive even a server reboot. Start tmux inside Mosh and you can detach and reattach later.
- Reduce latency on high-latency links. Mosh has a predictive local echo feature that makes typing feel instant even on high-latency connections. This is especially useful when working from a different continent.
- Change the UDP port range. If you can’t use 60000-61000, you can change the range by setting the
MOSH_PORTenvironment variable on the client, e.g.,MOSH_PORT=50000 mosh user@ip. The server must have those ports open as well. - Use a hostname instead of an IP. If your VPS has a domain name, use
mosh user@example.comto avoid remembering IP addresses.
Troubleshooting
- “mosh: Nothing received from server on UDP port…” This means the UDP ports are not reachable. Check your firewall rules on the VPS and your cloud provider’s security group. Also verify that the mosh-server process is running (you can check with
ps aux | grep mosh-server). - “mosh: Did not find mosh server startup message.” This usually indicates that the SSH connection succeeded but the mosh-server failed to start. Check if mosh is installed on the server (run
mosh-servermanually to see errors). Also ensure the server’s PATH includes the mosh binary. - Mosh connects but then hangs. This can happen if the UDP ports are partially blocked or if the connection is being dropped. Try increasing the timeout with
mosh --predict=experimentalor check if your ISP is throttling UDP. Sometimes using a different network (e.g., mobile hotspot) helps diagnose. - Can’t install mosh on the VPS. If the package is not found, update your package lists (
sudo apt update) or enable EPEL on CentOS. If your VPS is very minimal, you may need to install the ‘epel-release’ package first. - Mosh works but the session drops after a few minutes. This is often due to a firewall or NAT timeout that kills idle UDP connections. You can send keepalive packets by running a command like
watch -n 60 echo keepalivein the session, or configure your router to not drop idle UDP.
Frequently Asked Questions
Is Mosh secure?
Yes. Mosh uses SSH for authentication and the initial connection setup. After that, the data is encrypted with AES-128 in OCB mode, which is considered secure. However, Mosh does not support SSH agent forwarding or port forwarding, so for those features you need to use SSH.
Can I use Mosh on Windows?
Yes, but not natively. The easiest way is to use WSL (Windows Subsystem for Linux) and install Mosh inside the Linux environment. Alternatively, you can use the MSYS2 terminal, which provides a Unix-like environment. There is no native Windows binary that works as smoothly as on Unix-like systems.
Does Mosh work with IPv6?
Yes, Mosh supports IPv6. If your VPS has an IPv6 address, you can connect with mosh user@ipv6_address. Make sure your firewall allows UDP on the same ports for IPv6.
Can I use Mosh with a jump host (bastion)?
Mosh does not natively support jump hosts. However, you can use SSH’s ProxyJump feature by setting up an SSH config file that routes through the jump host, then Mosh will use that SSH connection. For example, in ~/.ssh/config, add a Host entry for the target server with ProxyJump user@jump_host.
How do I change the SSH port that Mosh uses?
Use the -p option followed by the port number, e.g., mosh -p 2222 user@ip. This tells Mosh to connect to SSH on port 2222. The UDP ports for the Mosh session are separate and default to 60000+.
Does Mosh consume more bandwidth than SSH?
Mosh can use more bandwidth because it sends frequent keepalive packets and has predictive echo. However, it also compresses data by default. In practice, the difference is small for typical terminal use, and the benefit of a stable connection outweighs the extra bandwidth.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Valheim Server Not Showing in Community List Fixes
- DisplayPort vs HDMI: Which Cable Should You Use?
- Soundbar vs 2.1 Speaker System: Which Is Better?
- Survive Lava for Brainrot Tier List170 points
- MySQL Dump Import: Fix Common Errors
- Mouse Moving on Its Own? Causes & Fixes