Installing mosh-server on Ubuntu, Debian, and Alpine requires adding the official distribution package, allowing incoming UDP traffic across ports 60000 to 61000, and verifying an active UTF-8 locale. The daemon bootstraps over an initial SSH session to provide persistent remote shell connections resilient to packet loss and IP roaming.
Network requirements and UDP ports for mosh-server
Mosh bootstraps the remote mosh-server binary via a preliminary OpenSSH connection that listens on TCP port 22 by default. Following successful public key or password authentication, the server launches the process on a negotiated UDP port within the 60000-61000 range and shuts down the interactive SSH channel to run via encrypted datagrams.
The server firewall must allow incoming packets on this port range to let mobile and desktop clients communicate. Unlike standard OpenSSH, Mosh does not implement TCP port forwarding or X11 forwarding, focusing its protocol strictly on input prediction, low latency, and connection recovery across unstable interfaces.
| Technical property | Standard OpenSSH | Mosh with mosh-server |
|---|---|---|
| Transport protocol | Persistent TCP with flow control | Encrypted UDP via State Synchronization Protocol |
| Firewall ports | TCP port 22 by default | UDP range 60000-61000 plus TCP 22 for setup |
| Client IP roaming | Session drops immediately upon IP change | Session persists seamlessly across networks |
| Port and X11 forwarding | Supported natively via command flags | Not implemented by design architecture |
When machines sit behind strict carrier-grade NAT without reachable public IPv4 addresses, administrators can deploy private mesh overlays such as Prialo secure mesh networking or Tailscale to establish direct links without opening arbitrary public firewall ports.
Installing mosh-server on Ubuntu and Debian using apt
The apt package manager provides mosh-server directly from Ubuntu and Debian base repositories without requiring third-party personal package archives. Installing the unified package delivers both client components and server binaries required by incoming connections.
sudo apt update
sudo apt install -y moshTo permit UDP packets across the default Ubuntu firewall configuration, configure the Uncomplicated Firewall (UFW) to accept the allocated port range:
sudo ufw allow 60000:61000/udp
sudo ufw status verboseIf the OpenSSH service listens on an alternate port, provide the connection string on the client via --ssh="ssh -p PORT". Regardless of the bootstrap port, mosh-server must reside in the target user system $PATH, typically installed at /usr/bin/mosh-server.
Configuring UTF-8 locales to prevent startup errors
Mosh enforces valid UTF-8 character encoding across both client and server environments. If system environment variables fall back to POSIX or C definitions lacking UTF-8 support, the remote mosh-server process exits immediately with a fatal diagnostic error during startup.
Minimal server images on Debian and Ubuntu often lack pre-generated non-ASCII locales. Run the following commands to generate and set the system-wide locale configuration:
sudo apt install -y locales
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8Verify the environment by checking the output of the locale command in an active SSH session; the LANG and LC_CTYPE variables must explicitly mention UTF-8 before launching Mosh.
Installing mosh-server on Alpine Linux using apk
Alpine Linux includes Mosh in its primary package repository managed through apk. Because Alpine uses the lightweight musl C library instead of glibc, UTF-8 compatibility is handled natively without invoking standalone locale-generation binaries.
apk update
apk add moshIf Alpine relies on iptables or nftables to restrict perimeter access, add a rule accepting datagrams within the expected UDP allocation range:
iptables -A INPUT -p udp --dport 60000:61000 -j ACCEPT
rc-service iptables saveEnsure the OpenSSH server daemon (sshd) runs on the Alpine host, since Mosh does not maintain a persistent background listener; it spawns mosh-server dynamically upon receiving an authenticated SSH invocation.
Mobile connections and session reliability with termi1
Using termi1 for mobile terminal sessions pairs Mosh with backend process managers to safeguard running tasks against accidental disconnection. When transitioning between Wi-Fi access points and cellular towers on phones, Mosh keeps the terminal responsive without resetting the remote terminal state.
Attaching commands to tmux on the remote machine guarantees that running tasks continue uninterrupted if the client application terminates. Within termi1, the specialized keyboard interface provides immediate access to essential control keys omitted by standard virtual keyboards, including Esc, Ctrl, Tab, and an auxiliary function row containing F1 through F12.
Cryptographic SSH keys generated directly on the phone remain stored inside hardware security enclaves without leaving the device. In addition, termi1 command assistance tools use guard modes to verify commands prior to submission, protecting remote systems against unintended destructive actions across erratic network links.
Frequently asked questions
Why does mosh-server require an initial SSH connection?
Mosh relies on OpenSSH on TCP port 22 to perform user authentication and securely exchange an ephemeral 128-bit session key. After establishing mutual trust, mosh-server opens a designated UDP socket, allowing the client to transition terminal traffic away from TCP.
How can a specific UDP port be defined for mosh-server?
The Mosh client supports the -p flag to designate a single UDP port rather than allowing dynamic selection across the default 60000-61000 range. Defining this explicit port simplifies incoming firewall rule configuration on infrastructure restricted by strict security perimeter rules.
What causes mosh-server to exit immediately with locale errors?
mosh-server terminates immediately if either the client or server environment reports a character set other than UTF-8. The synchronization protocol mandates full UTF-8 compatibility across both endpoints to accurately render and mirror terminal screen states without visual degradation.
Does mosh-server support standard SSH port forwarding?
mosh-server does not support TCP port tunneling, SOCKS proxying, or X11 forwarding capabilities found in standard OpenSSH. Its architecture explicitly focuses on terminal state synchronization over low-bandwidth or high-latency UDP connections, omitting generic stream multiplexing.