Strovent SystemsSign in
Reference

Can Mosh go through a jump host or bastion?

Why a jump host or ProxyJump does not carry a Mosh session, two ways to use Mosh anyway, and which Mosh options deal with the address it connects to.

Mosh cannot send its session through a jump host, because a jump host passes on a TCP connection and Mosh's session is UDP. You can still use Mosh with a bastion in one of the two ways below.

How Mosh connects

The Mosh manual describes two steps. First mosh uses ssh to reach the host and sign in, and runs mosh-server there. Then it closes the SSH connection and starts mosh-client, which opens a long-lived datagram connection over UDP. The manual states that Mosh requires UDP to pass between the client and the server.

A jump host only helps the first step. The SSH login can pass through it. The UDP step goes from your device to the server's address directly, and the jump host is not on that path.

Option 1: Mosh to the bastion, then SSH inside

Run Mosh to the bastion, and run SSH from there to the host behind it:

mosh [email protected]
ssh [email protected]

The manual's synopsis, mosh [options] [--] [user@]host [command...], also lets you give the command in one line:

mosh [email protected] -- ssh [email protected]

The Mosh session covers the path from your device to the bastion, so that part survives sleep and network changes. The connection from the bastion to the inner host is an ordinary SSH connection. For long work on the inner host, run tmux there. See Keep your work after a disconnect with tmux.

Option 2: the host itself accepts UDP from you

If the host behind the bastion can be reached directly over UDP from your device, for example over a VPN, Mosh can use it. The manual lists the options that control how it finds the address to connect to, --experimental-remote-ip:

  • proxy is the default. It uses SSH's --ssh-proxy-command option to get the exact address that ssh connects to. The manual says this may not work for environments where a bastion host forwards to a remote machine, and that it only works with OpenSSH.
  • remote uses the SSH_CONNECTION environment variable of the server. The manual says this is useful where ssh forwarding is used, or where --ssh-proxy-command is used for something else.
  • local resolves the host name given on the Mosh command line, and uses that address for both SSH and Mosh. It ignores ssh_config.

The name --experimental-remote-ip says the option is experimental, so test it before you depend on it. Use --ssh=COMMAND to change the ssh command Mosh starts, for example to add an option.

The UDP ports on the host must also be open. See Mosh "Nothing received from server on UDP port 60001".

Sources

Spotted a mistake? Email [email protected].